Skip to content
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

Unexpected behaviour constructing requests with query parameters values containing white spaces #56

Closed
ederparaiso opened this issue Jul 28, 2016 · 3 comments

Comments

@ederparaiso
Copy link

I'm not sure if its a bug or limitation of the lib. Maybe a future enhancement.
I have a request with a query param who value contains a white space.
I followed example bellow in README but it does not work:

  • The following will match either of these:
    • /with/parameters?search=search+terms&filter=month
    • /with/parameters?filter=month&search=search+terms
-  request:
      url: ^/with/parameters$
      query:
         search: search terms
         filter: month

My query param was

-  request:
     method: GET
     url: ^/test$
     query:
       term: "boo and foo"

And in jUnit test

 String request = "http://localhost:8882/test?term=boo and foo"

which is encoded and returns not found

404 [/test?term=boo+and+foo] Not Found 

So i changed de yml query param to "boo+and+foo" in order to match, but i'm still getting 404.

[35mLoaded: [GET] ^/test$?term=boo+and+foo]

404 [/test?term=boo+and+foo] Not Found 

The solution i found was encoding the '+' char in yml file:

query:
  term: "boo%2Band%2Bfoo"

And change my test to:

String request = "http://localhost:8882/test?term=boo+and+foo"

in order to encode "+" char to "%2B" and them match.

I think that is caused by regex processing, so i tried another test, escaping '+' symbol in yml file

query:
  term: "boo\\+and\\+foo"

In this way, i can write request strings in java without any encoding troubles as folowing:

String request = "http://localhost:8882/test?term=boo and foo"
[35mLoaded: [GET] ^/test$?term=boo\+and\+foo]

200 [/test?term=boo+and+foo] OK 

As i said, i'm not sure if it can be considered as a bug or lib's limitation. Maybe a future enhancement, or just an update in docs about this specific case. Another chars encoding does not have this problem.
I hope that it helps to improve this awesome lib. Thanks!

@azagniotov
Copy link
Owner

@ederparaiso Thanks for that. I apologise for the late reply. I will look into this

@azagniotov
Copy link
Owner

azagniotov commented Oct 19, 2016

Fixed in v4.0.0 You would have to stub as follows:

request:
     method: GET
     url: ^/test$
     query:
         term: "boo and foo"

Which should be match the stubbed if you are hitting from your browser:
http://localhost:8882/test?term=boo+and+foo
OR
if your URL is encoded in the code:
String request = "http://localhost:8882/test?term=boo%2Band%2Bfoo"

request:
     method: GET
     url: /spaces
     query:
         key: "['stalin and truman','are best friends']"

Which should be match the stubbed if you are hitting from your browser:
http://localhost:8882/spaces?key=['stalin+and+truman','are+best+friends']
OR
if your URL is encoded in the code:
String request = "http://localhost:8882/spaces?key=%5B%27stalin%2Band%2Btruman%27,%27are%2Bbest%2Bfriends%27%5D"

azagniotov added a commit that referenced this issue Oct 19, 2016
azagniotov added a commit that referenced this issue Oct 19, 2016
@azagniotov
Copy link
Owner

I added more examples in the docs. I hope this helps

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

No branches or pull requests

2 participants