Handle blank schemes when parrsing link URLs
This commit is contained in:
parent
7506ff3225
commit
bb16c9ca9f
|
@ -39,7 +39,11 @@ public struct GeminiParser {
|
||||||
let urlEnd = line.firstWhitespaceIndex(after: urlStart)
|
let urlEnd = line.firstWhitespaceIndex(after: urlStart)
|
||||||
let textStart = line.firstNonWhitespaceIndex(after: urlEnd)
|
let textStart = line.firstNonWhitespaceIndex(after: urlEnd)
|
||||||
|
|
||||||
let urlString = String(line[urlStart..<urlEnd])
|
var urlString = String(line[urlStart..<urlEnd])
|
||||||
|
if urlString.hasPrefix("//") {
|
||||||
|
// URL(string:relativeTo:) does not handle // meaning the same protocol as the base URL
|
||||||
|
urlString = baseURL.scheme! + ":" + urlString
|
||||||
|
}
|
||||||
// todo: if the URL initializer fails, should there be a .link line with a nil URL?
|
// todo: if the URL initializer fails, should there be a .link line with a nil URL?
|
||||||
let url = URL(string: urlString, relativeTo: baseURL)!.absoluteURL
|
let url = URL(string: urlString, relativeTo: baseURL)!.absoluteURL
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue