fix: encode # in query string as %23 to prevent URL truncation#1818
Draft
Bester1 wants to merge 2 commits intohttpie:masterfrom
Draft
fix: encode # in query string as %23 to prevent URL truncation#1818Bester1 wants to merge 2 commits intohttpie:masterfrom
Bester1 wants to merge 2 commits intohttpie:masterfrom
Conversation
added 2 commits
April 16, 2026 09:43
When a URL contains a # character inside query parameters (e.g., ?order_names[]=httpie#1001.1), Python's urlparse treats it as a fragment separator, causing everything after # to be dropped from the request. This is because requests/urllib3 strips fragments before sending. Now _process_url encodes # characters that appear after ? as %23, preserving them in the query string where they belong. Fixes httpie#1546
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.
Summary
When a URL contains a
#character inside query parameters (e.g.,?order_names[]=#1001.1), Python'surlparsetreats it as a fragment separator, causing everything after#to be dropped from the request. This is becauserequests/urllib3strips URL fragments before sending.This PR encodes
#characters that appear after?as%23in_process_url, preserving them in the query string where they belong.Fixes #1546
Test plan
http --offline get "http://example.com/api?order_names[]=#1001.1×tamp=1669900140"— now sends correct request with%23encoding#in query unaffected (no change in behavior)http://example.com/page#section) unaffected —#after?is encoded, but#before?is not