Don't encode colon if URLComponents path starts with colon #1139
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.
Apps can take a URL string like
which
URL
now allows (after the compatibility change to go back to allowing an empty scheme), and pass it toURLComponents(string:)
.URLComponents
follows RFC 3986, which says a scheme cannot be empty, so it interprets the whole string as a path. The app could then usecomponents.queryItems = ...
to assign query items and callcomponents.url
, which needs to generate the new.string
.During string generation,
URLComponents
percent encodes the colon at the beginning of the path, so theURL
returned does not have the scheme, host, and path it started out with. We can fix this by not percent-encoding any colons in the first path segment if the colon is the first character in the string.This still preserves the behaviors of both
URL
andURLComponents
:URL
can interpret the colon as an empty scheme like before, andURLComponents
, knowing that a scheme cannot be empty according to RFC 3986, can still interpret the string as a relative path.