Fix link lines with unescaped characters in the link not being parsed
This commit is contained in:
parent
66f318f0e7
commit
57ae52c090
|
@ -54,6 +54,11 @@ public struct GeminiParser {
|
||||||
|
|
||||||
if let url = URL(string: urlString, relativeTo: baseURL)?.absoluteURL {
|
if let url = URL(string: urlString, relativeTo: baseURL)?.absoluteURL {
|
||||||
doc.lines.append(.link(url, text: text))
|
doc.lines.append(.link(url, text: text))
|
||||||
|
} else if let escaped = urlString.addingPercentEncoding(withAllowedCharacters: .URLAllowed),
|
||||||
|
let url = URL(string: escaped, relativeTo: baseURL)?.absoluteURL {
|
||||||
|
// if URL initialization fails because there are unescaped chars in the doc, escape everything and try again.
|
||||||
|
// I'm not certain, but it feels unsafe to always do this escaping
|
||||||
|
doc.lines.append(.link(url, text: text))
|
||||||
} else {
|
} else {
|
||||||
let str: String
|
let str: String
|
||||||
if let text = text {
|
if let text = text {
|
||||||
|
@ -113,3 +118,7 @@ fileprivate extension String {
|
||||||
return index
|
return index
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private extension CharacterSet {
|
||||||
|
static let URLAllowed = CharacterSet(charactersIn: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~:/?#[]@!$&'()*+,;=%")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue