Skip to content

fix(matching): normalise header values using the header's own grammar - #14

Closed
YOU54F wants to merge 3 commits into
fix/repeated-headers-rfc9110from
fix/repeated-headers-normalise-grammar
Closed

YOU54F wants to merge 3 commits into
fix/repeated-headers-rfc9110from
fix/repeated-headers-normalise-grammar

Conversation

@YOU54F

@YOU54F YOU54F commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

Follow-up to pact-foundation#584 (stacked on its branch fix/repeated-headers-rfc9110).

Problem

Header value normalisation ignored the header's grammar, so a comma inside a Link target (<...>), a Via comment ((...)) or a quoted string was treated as a list separator. Values that differed only by whitespace there compared as equal. This happened in two places:

  • Repeated values: normalise_list always used the plain list grammar (the fast path in match_repeated_header).
  • Single values: with no matching rule, match_header_value normalised with split(',') + trim. The V2 engine's multi-value normalisation did the same.

Change

  • normalise_list(name, value) splits with Grammar::for_header(name), the same grammar used when matching each element.
  • match_header_value's no-rule fallback and the V2 engine (engine/mod.rs, execute_normalize_comma_whitespace) use normalise_list instead of the naive split. Whitespace around list commas is still ignored (RFC 9110 §5.6.1).
  • New shared cases (run on both the V1 and V2 matching engines):
    • singleton separate lines: Set-Cookie on separate lines still matches.
    • link whitespace inside target, via comment whitespace: no longer match (repeated values).
    • single link whitespace inside target, single via comment whitespace, single quoted whitespace: no longer match (single values).
    • single multi-value OWS: Cache-Control: no-cache,no-store vs no-cache, no-store still matches.
    • single multi-value quoted whitespace: Cache-Control: private="x,y" vs private="x, y" no longer matches.
    • unbalanced quote fallback: an unbalanced quote runs to the end of the value.
  • The no-rule per-line deprecation test now uses an unbalanced-quote example, since quoted whitespace no longer matches.
  • Mismatch messages name the failing value (7d06dcb).
    • When a repeated header fails a scalar rule (e.g. integer on REF-ID: 1111 / REF-ID: two), the joined mismatch is now followed by a per-line mismatch for each failing value, e.g. Expected 'two' to match an integer number for value at index 1.
    • Fixes the matcher path in match_header_lines, which reported every value as index 0. It now takes the index from the last path token.
    • Updated the match_header_with_a_values_matcher and V2 engine header_tests expectations to match.

Compatibility

No pact file format change. Matching is stricter in one way: whitespace inside a <URI>, a (comment) or a quoted string is now significant.

  • For repeated values this only affects this unreleased branch.
  • For single values it changes released behaviour (the naive split shipped in pact_ffi 0.5.3). For example, Cache-Control: private="x,y" used to match private="x, y" and now doesn't. That's RFC 9110 correct, but worth a release note.

The V2 engine still only normalises its known multi-value headers, so a custom single value a,b vs a, b still differs between the engines. That's unchanged here.

Testing

  • cargo test -p pact_matching: all pass.
  • Compatibility suite matrix across released / pr568 / this branch (go, .NET, php, python, ruby-ffi, rust): no scenario differs between labels. Before 7d06dcb, pact-php's runner failed one extra scenario on this branch, because the mismatch didn't name the failing value.
  • Cross-core probe (Rust / pact-jvm / pact-ruby v1): Link with whitespace inside the URI now mismatches at V2/V3/V4. No other changes.

🤖 Generated with Claude Code

YOU54F and others added 2 commits October 28, 2026 19:05
normalise_list split every header with the plain list grammar, so the fast
path treated whitespace inside Link targets (<...>) and Via comments (...)
as list separators. Values that differed only there compared as equal.
Split with Grammar::for_header(name) instead, and add cases for Link, Via
and Set-Cookie sent on separate lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lues

A header with one value on each side and no matching rule was compared after
splitting on every comma and trimming, so whitespace inside a Link <URI>, a Via
comment or a quoted string was ignored (`<https://a/?x=1, 2>` matched
`<https://a/?x=1,2>`). Use normalise_list, which only treats list-separating
commas as insignificant, in the legacy matcher and in the V2 engine's
multi-value header normalisation.

The "quoted OWS fallback" case relied on that and now mismatches; the per-line
deprecation warning test uses an unbalanced quote instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@YOU54F YOU54F changed the title fix(matching): normalise repeated headers using the header's own grammar fix(matching): normalise header values using the header's own grammar Oct 28, 2026
…scalar rule

A scalar rule on a repeated header reported only the joined mismatch
("Expected '1000, 1234, 9999ABC' to match '\d{1,4}'"), which doesn't say
which value failed. Report the per-line mismatches as well, and pass the
real list index to match_header_value in the matcher path instead of 0.

Fixes the V2 compatibility-suite scenario "Supports matchers for repeated
request headers (negative case)".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant