Fix/invalid url handling - issue 1832#3747
Open
rodrigobnogueira wants to merge 1 commit intoencode:masterfrom
Open
Fix/invalid url handling - issue 1832#3747rodrigobnogueira wants to merge 1 commit intoencode:masterfrom
rodrigobnogueira wants to merge 1 commit intoencode:masterfrom
Conversation
34c3a80 to
8e6d712
Compare
8e6d712 to
c02979c
Compare
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 Inconsistent Invalid URL Handling (Closes #1832 )
Summary
Fixed an inconsistency where URLs with a scheme but no host (e.g.,
https:/[google.com](http://google.com/)) raisedUnsupportedProtocolinstead ofInvalidURL.Problem
Previously, malformed URLs were handled inconsistently:
httpx.get('[https://😇](about:blank)')→InvalidURL(Correct)httpx.get('https:/[google.com](http://google.com/)')→UnsupportedProtocol(Incorrect)This occurred because
https:/[google.com](http://google.com/)(missing one slash) parses as a URL with a scheme but an empty host. Since it lacks a host, it's treated as a relative URL, whichhttpcorethen rejects as an unsupported protocol.Solution
Added validation in
httpx._client.Client._merge_urlto explicitly check for URLs that have a scheme but no host. These are now correctly identified as invalid, raisingInvalidURLwith a descriptive error message.Changes
httpx/_client.py: AddedInvalidURLcheck in_merge_urltests/client/test_invalid_url.py: Regression tests forhttps:/[google.com](http://google.com/)and[https:///google.com](about:blank)Verification
Checklist