diff --git a/SwiftBar/MenuBar/MenuBarItem.swift b/SwiftBar/MenuBar/MenuBarItem.swift index 0f901ea..fff2b1b 100644 --- a/SwiftBar/MenuBar/MenuBarItem.swift +++ b/SwiftBar/MenuBar/MenuBarItem.swift @@ -683,7 +683,7 @@ extension MenubarItem { } } - if let href = params.href, case let url = URL(string: href) ?? URL(fileURLWithPath: href), url.absoluteString != "." { + if let url = params.href?.getURL(), url.absoluteString != "." { if params.webView { showWebPopover(url: url, widht: params.webViewWidth, height: params.webViewHeight) } else { diff --git a/SwiftBar/Utility/String+Escaped.swift b/SwiftBar/Utility/String+Escaped.swift index cca1118..3f886f1 100644 --- a/SwiftBar/Utility/String+Escaped.swift +++ b/SwiftBar/Utility/String+Escaped.swift @@ -6,3 +6,19 @@ extension String { return "'\(self)'" } } + +extension String { + func getURL() -> URL? { + if let url = URL(string: self) { + return url + } + + var characterSet = CharacterSet.urlHostAllowed + characterSet.formUnion(.urlPathAllowed) + if let str = addingPercentEncoding(withAllowedCharacters: characterSet) { + return URL(string: str) + } + + return nil + } +}