Repository navigation
fix(matching): normalise header values using the header's own grammar - #602
Merged
Merged
Conversation
Normalize combined actual field lines during matching while preserving quoted commas, indexed matchers, singleton headers, and pact data. Add regression coverage for repeated custom header expectations.
Split combined custom-header values consistently for list matching, regardless of field-line grouping. Apply the same normalization in the V2 request and response plans while preserving quoted and JSON values, and add regression coverage.
The legacy matcher and the V2 plan builder each decided on their own which headers may be split on commas. Legacy split Content-Type and multi-value headers such as Cache-Control, while V2 skipped both, so the same pact verified differently depending on the engine. repeated_headers::header_kind now maps a header name to Singleton, Parameterised, MultiValue or Custom, using the lists in pact_models. Both engines split only Custom headers, which removes the Content-Type divergence: ["text/plain", "text/html"] no longer matches a single "text/plain, text/html" line in either engine. Tests pin that Content-Type and Cache-Control stay unsplit. Assisted-by: Claude Code:claude-opus-5-5
RFC 9110 §5.3 makes repeated field lines equivalent to one line with the values joined by commas. A repeated custom header without matchers now joins both sides with ", " and compares the results, ignoring whitespace around commas outside quoted strings and empty list elements. Both engines share this logic through `match_repeated_header`. The previous change split only the actual field lines on commas. That broke repeated values that contain commas themselves: `["a, b", "c"]` against the same lines, two `X-Sunset` dates, or two `Link` lines whose URIs hold commas. Joining both sides keeps the combined, separate and mixed `X-Request` groupings matching. When the joined comparison fails, the header falls back to the per-line comparison it used before. A pass through the fallback logs a deprecation warning: per-line matching of repeated headers is deprecated, and a future release will compare only the joined value. A failed fallback reports one mismatch for the joined comparison. The legacy engine extracts the per-line body of `match_header_maps` into `match_header_lines`. The V2 plan replaces `header:split-values` with `header:match-repeated`. A custom header with one expected value gains a `header:repeated` check, so a single actual line keeps the existing plan node. Headers with matching rules keep the actual-only split until matchers move onto the joined value. Changed expectations: - `match_headers_returns_a_mismatch_if_the_header_values_have_different_lengths` now reports the joined mismatch (`Expected 'd' to be equal to 'd, e'`). - The V2 plan snapshots in `engine/tests/header_tests.rs` show the new actions. `match_headers_with_number_type_matching_rule` reports the legacy engine's matcher message for repeated actual lines. Assisted-by: Claude Code:claude-opus-5-5
A repeated custom header with scalar matchers (Regex, Type, Integer and the like) on its own path is now matched as RFC 9110 §5.3 describes it: the expected and actual field lines are joined with commas and the matchers run once against each joined value. List-aware rules (MinType, MaxType, MinMaxType, EachValue, ArrayContains) and headers with indexed rules go through the actual-only split_header_field_lines, with no fallback, until the list-element commit. When the joined value fails but the field lines pass one at a time, the header still matches and logs the per-line deprecation warning. The warning also suggests wrapping the user's rule in EachValue, rendered as JSON, as the way to keep per-value matching once only the joined value is compared. Two existing expectations change under the joined semantics, and the mismatch now describes the joined value instead of one line: - engine header_tests match_headers_with_number_type_matching_rule: "Expected '1111, two' to match an integer number". - headers::tests::match_header_with_a_values_matcher: a Values rule is not list-aware, so a reordered list reports one mismatch between the two joined values. A header whose expected list is empty skips the repeated-header node in the V2 plan and the matcher tolerates an empty expected list, so it cannot panic. Assisted-by: Claude Code:claude-opus-5-5
…chers
List-aware matchers (MinType, MaxType, MinMaxType, EachValue,
ArrayContains) and index-specific matchers now see the list elements of
a repeated custom header. The elements come from the joined actual
value, so `3, 4` / `567` and `3` / `4` / `567` both give three elements.
The splitter honours RFC 9110 §5.6.4: commas inside quoted strings do
not separate elements, and `\` escapes inside quotes are respected. It
trims each element and drops empty ones (§5.6.1). It has no `{}` or `[]`
nesting, so a JSON-looking value splits at its commas like any other.
`normalise_list` shares the same tokenizer.
An indexed matcher triggers the split when it sits at `$.<key>.<n>` or
`$.<key>[<n>]` with `n` below the larger of the expected count and the
element count. Wildcard element rules at `$.<key>[*]` or `$.<key>.*`
address every element, so they count as list rules too. This replaces a
bare path-length check that caught any deeper path.
When the element match fails, the matcher retries over the field lines
as received, which is the old behaviour. A pass there logs a warning.
The warning says whole-line matching is deprecated, gives the element
count a future release will see, and points at RFC 9110 §5.5's advice to
quote values that contain commas. This keeps MaxType(2) against
`x, y` / `z`, and EachValue over unquoted dates or Link values, passing.
The PR's interim `split_header_field_lines`, which tracked brace and
bracket nesting, is removed. No existing test expectation changed: the
JSON-valued compatibility cases carry no rules, so they still go through
plain comparison.
Assisted-by: Claude Code:claude-opus-5-5
Splitting a repeated header into list elements cut every comma outside a quoted string. Two registered headers carry commas of their own: - Link (RFC 8288 §3): a comma inside `<…>` belongs to the target URI, as in `<https://a.example/?fields=id,name>; rel="next"`. - Via (RFC 9110 §5.6.5): a comma inside a `(…)` comment belongs to the comment, and comments nest. `split_list_elements` now keeps those commas, matching the header name case-insensitively. Every other header reads `<`, `>`, `(` and `)` as ordinary characters. Delimiters inside quoted strings do not count, and an unbalanced `<` or `(` extends to the end of the value, as an unbalanced quote does. `normalise_list` stays name-agnostic. Plain comparison normalises both sides the same way, so a comma inside `<…>` that both share is harmless. User-Agent and Server are singletons (their product comments may hold commas) and are never split. The "each-value link fallback" case no longer needs the per-line fallback, so it becomes "each-value link" with no warning. New cases cover a combined Link line and a MaxType rule on Via. Assisted-by: Claude Code:claude-opus-5-5
…ones The ArrayContains and EachValue X-Id tests had their inputs rewritten to combined field lines, which dropped coverage of the separate-line form that master tested. Restore the original inputs and add `_with_combined_field_lines` variants carrying the combined-line inputs with the same assertions. Also remove the two length asserts at the end of match_headers_combined_custom_header_compatibility. match_headers receives clones, so they cannot fail. Assisted-by: Claude Code:claude-opus-5-5
The "Matching Headers" section still said values are compared after stripping whitespace following commas. Describe the current rules: repeated custom headers compare by their comma-joined values per RFC 9110 section 5.3, list-aware and index-specific matchers see split elements (respecting quotes, Link angle brackets and Via comments), other matchers see the joined value, per-line-only matches pass with a deprecation warning, and single-value, Accept/Content-Type and known multi-value headers are unchanged. Assisted-by: Claude Code:claude-opus-5-5
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>
…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>
This was referenced Nov 12, 2026
YOU54F
added a commit
to YOU54F/pact-net
that referenced
this pull request
Nov 13, 2026
Updates the underlying Rust core from libpact_ffi 0.4.27 to 0.5.13, which moves the mock server to pact_mock_server v2 and brings a suite of improvements and bug fixes, including repeated custom headers continuing to match (pact-foundation/pact-reference#602). - Download pact_ffi from the cargo-dist `pact_ffi-v<version>` release: per-target .tar.xz/.zip archives, sha256 verified, with the shared library extracted to the same build/<os>/<arch>/ paths. - Refresh pact metadata to ffi 0.5.13 / models 1.3.18.
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.
Follow-up to #584, stacked on #568 → #584.
Note
This PR targets
masterso CI runs on the whole stack (test.ymlonly runs on non-draft PRs intomaster). The diff therefore includes the commits from #568 and #584. To review only this PR's changes, read the last three commits, or compare againstfix/repeated-headers-rfc9110.The whole stack (
fix/repeated-headers,fix/repeated-headers-rfc9110and this branch) was rebased ontomasterat 8e61686, with no conflicts. Moved from YOU54F#14.Problem
Header value normalisation ignored the header's grammar, so a comma inside a
Linktarget (<...>), aViacomment ((...)) 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:normalise_listalways used the plain list grammar (the fast path inmatch_repeated_header).match_header_valuenormalised withsplit(',')+ trim. The V2 engine's multi-value normalisation did the same.Change
normalise_list(name, value)splits withGrammar::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) usenormalise_listinstead of the naive split. Whitespace around list commas is still ignored (RFC 9110 §5.6.1).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-storevsno-cache, no-storestill matches.single multi-value quoted whitespace:Cache-Control: private="x,y"vsprivate="x, y"no longer matches.unbalanced quote fallback: an unbalanced quote runs to the end of the value.integeronREF-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.match_header_lines, which reported every value as index 0. It now takes the index from the last path token.match_header_with_a_values_matcherand V2 engineheader_testsexpectations 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.Cache-Control: private="x,y"used to matchprivate="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,bvsa, bstill differs between the engines. That's unchanged here.Testing
cargo test -p pact_matching: all pass (522 + 823) after the rebase ontomaster.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):
Linkwith whitespace inside the URI now mismatches at V2/V3/V4. No other changes.E2E: a fork prerelease,
pact_ffi-v0.5.13-rc.1on YOU54F/pact-reference, is being consumed by draft PRs in pact-js-core, pact-python, pact-net, pact-ruby-ffi, pact-ruby, pact-php, pact-js and pact-go. Results will follow.🤖 Generated with Claude Code