diff --git a/Sources/Publish/API/Website.swift b/Sources/Publish/API/Website.swift index fd4c5b8c..5b000a30 100644 --- a/Sources/Publish/API/Website.swift +++ b/Sources/Publish/API/Website.swift @@ -224,6 +224,8 @@ public extension Website { /// - parameter path: The path to return a URL for. func url(for path: Path) -> URL { guard !path.string.isEmpty else { return url } + guard !path.string.hasPrefix("http://") else { return URL(string: path.string) ?? url } + guard !path.string.hasPrefix("https://") else { return URL(string: path.string) ?? url } return url.appendingPathComponent(path.string) } diff --git a/Tests/PublishTests/Tests/WebsiteTests.swift b/Tests/PublishTests/Tests/WebsiteTests.swift index 1ab15744..aa25d7f9 100644 --- a/Tests/PublishTests/Tests/WebsiteTests.swift +++ b/Tests/PublishTests/Tests/WebsiteTests.swift @@ -72,6 +72,13 @@ final class WebsiteTests: PublishTestCase { URL(string: "https://swiftbysundell.com/a/path") ) } + + func testURLForPathContainingAbsoluteURL() { + XCTAssertEqual( + website.url(for: Path("https://swiftbysundell.com/a/path")), + URL(string: "https://swiftbysundell.com/a/path") + ) + } func testURLForLocation() { let page = Page(path: "mypage", content: Content())