-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
gh-76960: Fix urljoining with an empty query string. #5645
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 |
---|---|---|
|
@@ -535,7 +535,10 @@ def urljoin(base, url, allow_fragments=True): | |
if not path and not params: | ||
path = bpath | ||
params = bparams | ||
if not query: | ||
# since urlparse doesn't leave any evidence of whether there was a bare | ||
# '?' with an empty query string, we need to check whether it was there. | ||
has_empty_query = url[0] == '?' or url.startswith(scheme + ':?') | ||
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. What is this The behavior in Ruby and Golang was different for this scenario (but consistent).
And with golang https://go.dev/play/p/lui16M9pFyo
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. If this condition is removed 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. From https://datatracker.ietf.org/doc/html/rfc3986#section-5.2.2:
For now, But testing only |
||
if not has_empty_query: | ||
query = bquery | ||
return _coerce_result(urlunparse((scheme, netloc, path, | ||
params, query, fragment))) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix urljoining with '?', a URL containing only a bare query string. |
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.
this is the test case that @orsenthil suggests is wrong as it doesn't match other languages which result in
http:?
as the output.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.
Yes, that's correct. We need to remove this. Perhaps I will modify this and bring this PR to a close.