From bb1161baa9c7f22665dab59e76e1629ef2fd61a4 Mon Sep 17 00:00:00 2001 From: JinguBangWest Date: Thu, 2 May 2024 22:05:57 -0400 Subject: [PATCH] Refactor strip_web_protocol This allows for more prefixes to be added in the future if needed without repeating code multiple times. --- tagstudio/src/core/utils/web.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tagstudio/src/core/utils/web.py b/tagstudio/src/core/utils/web.py index 08072594..d42ef782 100644 --- a/tagstudio/src/core/utils/web.py +++ b/tagstudio/src/core/utils/web.py @@ -4,9 +4,8 @@ def strip_web_protocol(string: str) -> str: """Strips a leading web protocol (ex. \"https://\") as well as \"www.\" from a string.""" - new_str = string - new_str = new_str.removeprefix('https://') - new_str = new_str.removeprefix('http://') - new_str = new_str.removeprefix('www.') - new_str = new_str.removeprefix('www2.') - return new_str + prefixes = ['https://','http://','www.','www2.'] + for prefix in prefixes: + if string.startswith(prefix): + string = string.replace(prefix, '') + return string