Allow square brackets in Swift CFURL path, query, and fragment#1802
Merged
jrflat merged 2 commits intoswiftlang:mainfrom Mar 10, 2026
Merged
Allow square brackets in Swift CFURL path, query, and fragment#1802jrflat merged 2 commits intoswiftlang:mainfrom
jrflat merged 2 commits intoswiftlang:mainfrom
Conversation
Contributor
Author
|
@swift-ci please test |
itingliu
reviewed
Mar 9, 2026
Contributor
itingliu
left a comment
There was a problem hiding this comment.
It looks like this codepath is available everywhere, not just behind #if FOUNDATION_FRAMEWORK? If so would it be possible to add a test for this change even though there's no public Swift URL API that exercises this path?
Contributor
Author
Sure the internal function should be testable, I can add a test |
Contributor
Author
|
@swift-ci please test |
This was referenced Mar 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Allow
"["and"]"to exist unencoded in the path, query, and fragment ofCFURL.Motivation:
The old
CFURLimplementation allowed"["and"]"anywhere in the URL string due to a quirk of how IPv6 literals were implemented (despite both RFC 3986 and the old RFC 1808 only allowing those characters in the host component). We should match this behavior for the path, query, and fragment components for compatibility with both the old implementation and the WHATWG URL spec as a bonus.Modifications:
"["and"]"unencoded in the path, query, and fragment componentsaddPercentEscapesfunction used during string encoding to use the newer, fasterURLComponentAllowedSetimplementation, which I forgot to do earlier. The olderURLComponentAllowedMaskbitmasks used byURLComponentsand theCFURL/NSURLfile path initializers still behave the same as before and as expected for those APIs. We can investigate allowing"["and"]"for those separately.Result:
CFURLagain allows"["and"]"in path, query, and fragment components and does not returnNULL.Testing:
CFURL/NSURLunit test with the Swift implementation enabled.