| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -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 | ||
|
Comment thread
Copy link
Copy Markdown
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. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityWhy 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 .: is no more legal than https: according to RFC 3986.
Sorry, something went wrong.
All reactions
|
||
|
|
||
| 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 | ||
| Expand Down | ||
| 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] |
| Back | FazBrowse Home | New Git URL |
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Qualityconfusion with a protocol-relative URL? [as opposed to a host-relative URL]
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.