Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
gh-87389: avoid treating path as URI with netloc#93894
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
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
4f76c4406b387900a3a92a8e1cc283c8332f99e80be542578b7b0b156915331915451c952a0f4899f512a00656c8985853f1f94ae8a34cd023d4b567a71381d18bbd9File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -517,14 +517,32 @@ def urlunparse(components): | ||
| url = "%s;%s" % (url, params) | ||
| return _coerce_result(urlunsplit((scheme, netloc, url, query, fragment))) | ||
| # Returns true if path can confused with a scheme. I.e. a relative path | ||
| # without leading dot that includes a colon in the first component. | ||
| _is_scheme_like = re.compile(r'[^/.][^/]*:').match | ||
Member 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. Why the special allowance for a leading dot? Is there a test case for it? Yes, a scheme cannot start with a dot, but a path-noscheme component of | ||
| def urlunsplit(components): | ||
| """Combine the elements of a tuple as returned by urlsplit() into a | ||
| complete URL as a string. The data argument can be any five-item iterable. | ||
| This may result in a slightly different, but equivalent URL, if the URL that | ||
| was parsed originally had unnecessary delimiters (for example, a ? with an | ||
| empty query; the RFC states that these are equivalent).""" | ||
| scheme, netloc, url, query, fragment, _coerce_result = ( | ||
| scheme, netloc, path, query, fragment, _coerce_result = ( | ||
| _coerce_args(*components)) | ||
| if not scheme and not netloc: | ||
| # Building a relative URI. Need to be careful that path is not | ||
| # confused with scheme or netloc. | ||
| if path.startswith('//'): | ||
| # gh-87389: don't treat first component of path as netloc | ||
| url = '/' + path.lstrip('/') | ||
| elif _is_scheme_like(path): | ||
| # first component has colon, ensure it will not be parsed as the | ||
| # scheme | ||
| url = './' + path | ||
| else: | ||
| url = path | ||
| else: | ||
| url = path | ||
| if netloc or (scheme and scheme in uses_netloc) or url[:2] == '//': | ||
| if url and url[:1] != '/': url = '/' + url | ||
| url = '//' + (netloc or '') + url | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Change :func:`urllib.parse.urlunsplit` to sanitize ``path`` argument in order | ||
| to avoid confusing the first component of the path as a net location or | ||
| scheme. | ||
| Co-authored-by: Gregory P. Smith <greg@krypto.org> [Google] |
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.
confusion with a protocol-relative URL? [as opposed to a host-relative URL]