URLComponents.string should percent-encode colons in first path segment if needed #1117
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.
The following code can recursively call
.path()
, causing an infinite loop.The issue is that
self.path()
calls.absoluteURL.path()
ifself
has a base URL..absoluteURL
should never have a base URL, so this shouldn't recurse. However, ifURL(string: absoluteString)
fails like it does in this example, then.absoluteURL
returnsself
, causing the recursion.In the example above, merging the relative and base paths gives us
./not%20a%20scheme:
since they are both relative. Then, we remove the dot segments as specified by the RFC algorithm, giving usnot%20a%20scheme:
. We assign this to aurlComponents.percentEncodedPath
, then when we're finished building the components, we callurlComponents.string
to get the absolute string.URLComponents.string
should always return a parsable URL string, ornil
. In this case, the string that's returned isnot%20a%20scheme:
, which is not valid.This PR fixes the issue by:
URLComponents.string
, but only if the colons could be mistaken as a scheme separator.absoluteURL.relativePath()
instead to ensure that we never recurse.