Handle blank schemes when parrsing link URLs

This commit is contained in:
Shadowfacts 2020-12-21 17:53:47 -05:00
parent 7506ff3225
commit bb16c9ca9f
1 changed files with 5 additions and 1 deletions

View File

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