-
Notifications
You must be signed in to change notification settings - Fork 214
Fix-prevented "?" from being added in case query is empty #1650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -711,7 +711,7 @@ internal struct RFC3986Parser { | |
| finalURLString += path | ||
| } | ||
|
|
||
| if let query = parseInfo.query { | ||
| if let query = parseInfo.query, !query.isEmpty { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This strips empty query components from URL strings that require percent-encoding, but otherwise does not strip the query component, which seems inconsistent. For example, this would give us:
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can add this implantation if this is the only thing that is left 😅 but this may rise another question should we remove "?" in case of the API's user added explicitly "?" in the url in this case: |
||
| if invalidComponents.contains(.query) { | ||
| finalURLString += "?\(percentEncode(query, component: .query)!)" | ||
| } else { | ||
|
|
@@ -1322,7 +1322,7 @@ extension RFC3986Parser { | |
| finalURLString += path | ||
| } | ||
|
|
||
| if let query = parseInfo.query { | ||
| if let query = parseInfo.query, !query.isEmpty { | ||
| if invalidComponents.contains(.query) { | ||
| finalURLString += "?\(percentEncode(query, component: .query, skipAlreadyEncoded: true)!)" | ||
| } else { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1115,7 +1115,7 @@ internal final class _SwiftURL: Sendable, Hashable, Equatable { | |
| result += ":\(portString)" | ||
| } | ||
| result += path | ||
| if let query { | ||
| if let query, !query.isEmpty { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This affects |
||
| result += "?\(query)" | ||
| } | ||
| if let fragment { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a client wants to add an empty query component to the string via:
this would make that use-case impossible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not the same outcome though,
http://example.com/has no query andhttp://example.com/?has an empty query. These are semantically different according to URL standards.In fact, RFC 3986 lists this exact example in Section 6.2.3 (emphasis mine):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An application/server could definitely distinguish between having no query vs. an empty query. For example, an application might decide that:
In this case, they might have logic to call
url.appending(queryItems: userAttributes)if the user has already visited their profile, even ifuserAttributesis empty.But overall, I think the main point is that the URL standards differentiate no query vs. empty query, so we shouldn't restrict how developers might use this semantic difference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are totally right