Add percent encoding to local URLs #261

This commit is contained in:
Alex Mazanov 2022-04-16 14:10:58 -04:00
parent e84e498c41
commit b4ef58244b
No known key found for this signature in database
GPG Key ID: FD35C3C7C1D34AB4
2 changed files with 17 additions and 1 deletions

View File

@ -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 {

View File

@ -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
}
}