Skip to content

fix: encode # in query string as %23 to prevent URL truncation#1818

Draft
Bester1 wants to merge 2 commits intohttpie:masterfrom
Bester1:fix-hash-in-query-string
Draft

fix: encode # in query string as %23 to prevent URL truncation#1818
Bester1 wants to merge 2 commits intohttpie:masterfrom
Bester1:fix-hash-in-query-string

Conversation

@Bester1
Copy link
Copy Markdown

@Bester1 Bester1 commented Apr 16, 2026

Summary

When a URL contains a # character inside query parameters (e.g., ?order_names[]=#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 URL fragments before sending.

This PR encodes # characters that appear after ? as %23 in _process_url, preserving them in the query string where they belong.

Fixes #1546

Test plan

  • Verified with http --offline get "http://example.com/api?order_names[]=#1001.1&timestamp=1669900140" — now sends correct request with %23 encoding
  • All 38 existing CLI tests pass
  • URL without # in query unaffected (no change in behavior)
  • URL with legitimate fragment (e.g., http://example.com/page#section) unaffected — # after ? is encoded, but # before ? is not

Thor Agent 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hash character # in a query string causes the rest of the string to be ignored

1 participant