Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/FoundationEssentials/URL/URL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1847,7 +1847,7 @@ public struct URL: Equatable, Sendable, Hashable {
var components = URLComponents(parseInfo: _parseInfo)
let newPath = components.percentEncodedPath.removingDotSegments
components.percentEncodedPath = newPath
return components.url(relativeTo: baseURL)!
return components.url(relativeTo: baseURL) ?? self
}

/// Standardizes the path of a file URL by removing dot segments.
Expand Down
2 changes: 1 addition & 1 deletion Sources/FoundationEssentials/URL/URLComponents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ public struct URLComponents: Hashable, Equatable, Sendable {
return CFURLCreateWithString(kCFAllocatorDefault, string as CFString, nil) as URL?
}
#endif
return URL(string: string)
return URL(string: string, relativeTo: nil)
}

/// Returns a URL created from the URLComponents relative to a base URL.
Expand Down
6 changes: 6 additions & 0 deletions Tests/FoundationEssentialsTests/URLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,12 @@ final class URLTests : XCTestCase {
XCTAssertEqual(comp.path, "/my\u{0}path")
}

func testURLStandardizedEmptyString() {
let url = URL(string: "../../../")!
let standardized = url.standardized
XCTAssertTrue(standardized.path().isEmpty)
}

#if FOUNDATION_FRAMEWORK
func testURLComponentsBridging() {
var nsURLComponents = NSURLComponents(
Expand Down