NSURL dataRepresentation inits should allow some invalid URLs the old parser accepted#1810
Merged
jrflat merged 2 commits intoswiftlang:mainfrom Apr 2, 2026
Merged
Conversation
Contributor
Author
|
@swift-ci please test |
Contributor
Author
|
@swift-ci please test Windows Platform |
…he old parser accepted
868a437 to
fa99eef
Compare
Contributor
Author
|
@swift-ci please test |
Contributor
Author
|
@swift-ci please test |
jmschonfeld
approved these changes
Apr 1, 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.
Fix Swift
CFURLparsing to accept some invalid URL strings that the old parser accepted for data representation inits.Motivation:
CFURLCreateWithBytesandCFURLCreateAbsoluteURLWithBytesgenerally accept any input and percent-encode it until it's valid. However, the new Swift code path for these functions rejected some invalid URL formats. This caused+[NSURL (absolute)URLWithDataRepresentation:]to returnnilfor data that previously succeeded, such as IP-literal hosts with invalid characters, unterminated[brackets, and relative paths with:in the first segment.Modifications:
[, and colon-in-relative-path rejection onuseModernParsing: true, so theCFURLbyte encoding path is as lenient as the old parser.CFURL, preserve the[and]bracket delimiters and only percent-encode the inner content.span.extracting(_:)more often for safer index validation.Result:
Data representation inits accept the same URL strings as the old parser.
Testing:
Added unit tests for data representation
NSURLs with invalid IP-literals, unterminated brackets, spaces in hosts, and relative paths with colons.