Compatibility behaviors for Swift URL #1113
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses main behavioral differences of the new Swift
URL
implementation in order to preserve bincompat.URL
. This was the behavior in the old implementation, and can causeURL
to return different components for URL strings starting with:
.nil
host for URLs likehttps:///
instead of returning empty string. RFC 3986 suggests this should be an empty string, but I don't think this conformance outweighs compatibility here.URL(filePath:)
will check for fullfile:
andhttp:
URL strings that were incorrectly passed. It drops thefile:
scheme or passes thehttp:
string toURL(string:)
instead. It also logs an "API MISUSE" fault in these cases. This fixes apps that rely on old buggy behavior where passing a full URL string asfilePath
could happen to work itself out if a different API like.appendingPathComponent(_:)
is called immediately after..appending(component:)
behave like.appending(path:)
for file URLs, so that it does not percent-encode/
to%2F
. The old implementation had a bug where this actually didn't happen for file URLs, so we should maintain that old behavior to prevent breakage.URL(string:relativeTo:)
returningnil
for empty string and instead uses an internalURL(stringOrEmpty:relativeTo:)
in cases where we do need to initialize with the empty string, such as when.deletingLastPathComponent()
of a single-component path. We can still pass the empty string RFC tests usingURL(stringOrEmpty:relativeTo:)
../
or.