Skip to content

Fix _parse_header_links() when parameter value contains '=' - #3890

Open
xtianWang wants to merge 1 commit into
encode:masterfrom
xtianWang:fix/link-parameter-equals
Open

xtianWang wants to merge 1 commit into
encode:masterfrom
xtianWang:fix/link-parameter-equals

Conversation

@xtianWang

Copy link
Copy Markdown

Summary

In httpx._models._parse_header_links(), splitting link parameters with param.split("=") raises ValueError when a parameter value itself contains = (e.g. Link: </page/2>; title="a=b"; rel="next"). Because the surrounding except ValueError: break aborts parsing that link, both the parameter and any subsequent parameters such as rel="next" are silently dropped.

This PR changes the split to param.split("=", 1) and adds a regression test in tests/models/test_headers.py.

Verification

  • pytest -q tests/models/test_headers.py: 28 passed

@suirindo

suirindo commented Dec 3, 2026

Copy link
Copy Markdown

The split-once fix preserves rel="next" for title="a=b". I checked one nearby case at 913d367: </page/2>; title="edition=2; draft"; rel="next" still produces a truncated title and drops rel because the semicolon split does not respect quoted values. This predates the PR, so I would keep it separate rather than block the equals-sign fix. AI-assisted review; I ran the parser directly with a synthetic header and made no requests.

@Mansi2221 Mansi2221 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One-character fix with real impact. RFC 8288 allows parameter values to contain = (especially when quoted), and param.split("=") with no limit raised ValueError on title="a=b" and triggered the except ValueError: break which silently dropped all remaining parameters on that link — including rel, which the Response.links dict uses as the key.

So a Link: </page/2>; title="a=b"; rel="next" header previously disappeared entirely from response.links. The maxsplit=1 correctly splits only on the first =.

Test covers the exact scenario. Could also add a case where the value contains multiple = (e.g. base64-encoded token in a state= param), but the single-= case is representative.

LGTM.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants