Skip to content

fix: Send each query parameter value at its own index - #27

Merged
surpher merged 1 commit into
surpher:mainfrom
mkieselmann:fix/query-param-multiple-values
Jul 30, 2026
Merged

fix: Send each query parameter value at its own index#27
surpher merged 1 commit into
surpher:mainfrom
mkieselmann:fix/query-param-multiple-values

Conversation

@mkieselmann

@mkieselmann mkieselmann commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Problem

Interaction.Request.queryParam(name:values:) joined all values with a comma and passed the result to pactffi_with_query_parameter_v2 at index 0. An expectation set up with ["foo", "bar"] was therefore recorded as the single value "foo,bar", so a consumer actually sending ?item=foo&item=bar failed to match its own pact:

QueryMismatch: Expected query parameter 'item' with value 'foo,bar' but was 'foo'
QueryMismatch: Expected query parameter 'item' with value '' but was 'bar'
QueryMismatch: Expected query parameter 'item' with 1 value(s) but received 2 value(s)
 Expected: ["foo,bar"]
 Actual: ["foo", "bar"]

This makes repeated query keys impossible to contract-test.

History

The correct behaviour was implemented in 4c01bec already but has been replaced it with values.joined(separator: ",") and a single index-0 call.
A fix has been applied in 5cd4fab, but only for headers not for the query.

withHeader(handle:name:values:interactionPart:) has kept the correct shape ever since and served as the template for this fix.

Change

withQueryParameter now mirrors withHeader and calls the FFI once per value with its offset, so each value is recorded as its own occurrence of the key.

File Change
Sources/Protocols/PactFFIProviding.swift withQueryParameter(handle:name:value: String)values: [String]
Sources/Services/DefaultPactFFIProvider.swift Indexed values.enumerated() loop; empty array delegates to withQueryParameterWithoutAssociatedValue
Sources/Model/Interaction+Request.swift Dropped the joined(separator:); documented multi-value and empty-array semantics
Tests/Support/MockPactFFIProvider.swift Conformance updated to the new signature
Tests/PactBuilderTests.swift Tests no longer encode the buggy behaviour; adds a regression test

The public API (queryParam(name:values:)) is unchanged — this only corrects how those values reach the FFI.

Behaviour change

An empty values array previously produced ?name= (empty-string value, via [].joined() == ""). It now produces ?name with no associated value, by delegating to the — until now unreachable — withQueryParameterWithoutAssociatedValue, matching the NULL form documented by the FFI. The existing testInteractionWithQueryParameters case ("baz", []) was updated accordingly.

@mkieselmann
mkieselmann force-pushed the fix/query-param-multiple-values branch 2 times, most recently from b0fc686 to 77fecd1 Compare July 29, 2026 16:03
@mkieselmann
mkieselmann force-pushed the fix/query-param-multiple-values branch from 77fecd1 to baf7667 Compare July 29, 2026 16:07
@surpher
surpher merged commit b0794ab into surpher:main Jul 30, 2026
@mkieselmannPDG

mkieselmannPDG commented Jul 31, 2026

Copy link
Copy Markdown

@surpher Thanks for looking into this and merging the PR. Would you mind creating a new Release with that fix so that we can use it in https://github.com/surpher/PactSwift/tree/feat/v2.0.0?

@pepejeria

Copy link
Copy Markdown

Hi @surpher, just checking if it would be possible to create a new release with this. I could then create a PR to have PactSwift consume the new version. Thanks.

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.

4 participants