-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with URL Encoding of space character in query parameter #125
Comments
Hmm, the + is weird, we are guessing that is coming from the mock server. However, if the provider is expecting a url encoded string, I feel like that should be part of the contract (and what your client will need to do). i.e. shouldn't the mock be mockServiceInstance
.uponReceiving("example request")
.given("example")
.withRequest(
method: .GET,
path: "/example/odata",
query: ["$orderby": "CreatedAt%20desc"]
)
.willRespondWith(status: 200) |
That may cause the ampersand to be double encoded, as the query with the hash format expects unencoded params. I don't think this can be fixed unfortunately, as it's part of the underlying behaviour of the Ruby encoding library. I'm afraid you'll have to post process the pact file (find and replace) before it's published. |
Oh hey, I know this one! The RFC 3986 defines the URL syntax, which is mostly about the separate parts of a URL, what they're for, and what characters can go there. It doesn't define any structure to the query string, but it does say that As a server, you don't know what content type you have in a query string. But you do know:
tl;dr: both Of course, it's ideal if the pact can perfectly match what is actually sent by your client. Does |
Only after spending 30 minutes writing that up do I see that Beth already linked to a summary of |
But you summarised it so nicely! They should link to YOUR explanation. |
Unfortunately, what servers should do and what they do do are two different things. |
Beth is right about double percentage encoding if writing the test with // declaring
query: ["$orderby": "CreatedAt%20desc"]
// yeilds
query: "$orderby=CreatedAt%2520desc" A way to get Changes in #126 explicitly convert literal spaces into |
In this version of the pact specification, you can actually specify the query string as a string, and it's expected that it is encoded when the user specifies the string, so that's probably the best solution in this case. I believe this is not supported in later versions of the specification though, which is something I kept meaning to bring up, but it never got to the top of the priority list. |
Based on what @bethesque wrote, @thomas-br does the test/contract work per your expectations if you write your test like: .withRequest(
method: .GET,
path: "/example/odata",
query: "$orderby=CreatedAt%20desc"
)
.willRespondWith(status: 200) |
@surpher Yes it does. The only downside of the way shown in the snipped is that it introduces a strict checking of the order of the query params if there are multiple ones. |
Yeah I understand and was wondering about that. @bethesque when passing a string for |
I thought I did some magic logic in there to do a smarter match, but if @thomas-br has tested it any found that the order makes a difference, then I must be thinking of something else. |
Part of the problem is that it's not easy to know what format the query string is in. By convention (but not standard), they're |
In pact artifact files generated out of pact-consumer-swift tests I am facing issues with URL encoding.
With the example test:
In the pact file under interaction, the URL is constructed like the following:
The space in query is unfortunately encoded as a
+
instead of a%20
which is leading to issues with certain providers running the verification against their systems. Some libraries seem to be very picky of the expected escaped space whether to expect%20
or+
. This is currently blocking the implementation of pact tests on provider side.Is there a way of configuring pact-consumer-swift to escape with a
%20
or somehow influence how the pact json is generated?The text was updated successfully, but these errors were encountered: