1

When I try to pass "+" sign as a part of query parameter in different ways, it encodes any of the results.

I expect to pass phone parameter with +380999418260 value.

Tried the most expected right way:

request:
  method: GET
  url: /customers/prepaid
  queryParameters:
    phone: "%2B380999418260"
  headers:
    Content-Type: application/x-www-form-urlencoded

Also tried to pass directly from url:

request:
  method: GET
  url: /customers/prepaid?phone=%2B380999418260
  headers:
    Content-Type: application/x-www-form-urlencoded

Both says that phone is %2B380999418260

From the logs, it converts the % sign:

"X-Query-String":"phone=%252B380999418260"

I also tried to pass it non-encoded:

request:
  method: GET
  url: /customers/prepaid
  queryParameters:
    phone: "+380999418260"
  headers:
    Content-Type: application/x-www-form-urlencoded

But in this case it converts the + sign to space character.

When I access this endpoint from Postman with this uri /customers/prepaid?phone=%2B380999418260 it returns the correct response, where the correct phone with "+" sign is used.

1 Answers1

0

According to this question, you can't pass + symbol directly, it should be encoded. But on the server side you can decode received string using URLDecoder class:

String myString = "%2B380999418260";
URLDecoder.decode(myString, "ISO-8859-1");
// output: +380999418260
Golov Pavel
  • 624
  • 5
  • 15
  • @Pavel I used reverse function `URLEncoder.encode("+380999418260")` to encode my string for url. But anyways, the issue that using Spring Cloud Contract - I can't pass the plus sign correctly, but I succeeded with Postman. So the issue with the Spring tool. – Maksym Nyrka May 11 '19 at 13:27
  • Can you explain what you are trying to do? You send the request by url ```/customers/prepaid?phone=%2B380999418260``` and what the next? – Golov Pavel May 11 '19 at 13:38
  • When I do it from Postman - the `%2B380999418260` successfully converted to `+380999418260` and the correct response is returned. But when I do it from Spring Cloud Contract - it doesn't convert `%2B380999418260` to anything, the service says that `%2B380999418260` is not correct parameter. – Maksym Nyrka May 11 '19 at 14:28
  • Did you try this? ```url: /customers/prepaid?phone=+380999418260```. I think it may work. – Golov Pavel May 11 '19 at 18:11
  • Yes, I tried that. It becomes `phone= 380999418260`. The plus sign is converted to space character. – Maksym Nyrka May 13 '19 at 06:49
  • @MaksymNestrymannyj I am experiencing the same behavior in my own contract tests. In my case i have a url path parameter that contains a space ("%20" while url encoded). The test will fail on the producer side if i dont produce the contract test with spaces as follows "/somebase/this is my problem". However when i run the test on the consumer side if i dont provide the %20 on the expected url it will fail. I have to then provide another contract like so "somebase/this%20is%20my%20%problem. After debugging i come to realize the producer side is not decoding the path. Have you solved this? – czgaljic Apr 25 '21 at 14:21
  • @czgaljic I haven't resolved the issue with automatic conversion. I've just changed the test case data and removed "+" sign from it, so the unwanted conversion won't happen at all. – Maksym Nyrka Jan 23 '23 at 11:33