Rest-assured: Dollar Sign in URL getting encoded

Created on 1 Dec 2017  路  5Comments  路  Source: rest-assured/rest-assured

Seems to be an issue with URL encoding

We have an endpoint to get the with $ sign

http://localhost:8080/myaccount/rest/v1/orders/$count

So when we send the request the URL is encoded as

http://localhost:8080/myaccount/rest/v1/orders/%24count

But $ is a reserved URL character per the below spec and should be ok to use like other reserved characters ( +, *, / , : etc.) which don鈥檛 get encoded

https://tools.ietf.org/html/rfc3986#section-2.2

Other framework like jersyclient , angular, springresettemplate all respects this and not encode $ sign.

The workaround is to disable the URL encoding , but shouldn't be this taken care and not encoded at first place.

Most helpful comment

there is a work-around with RequestSpecBuilder:
RequestSpecification spec = new RequestSpecBuilder().setUrlEncodingEnabled(false); spec.setBaseUri(...);
Then it won't escape the $ character.

All 5 comments

REST Assured is using java.net.URLEncoder to encode the URL. Feels strange that it shouldn't work as expected?

Maybe it's not as strange though, reading the javadoc it says that it's intended for encoding "application/x-www-form-urlencoded" contents. Didn't know that this was different than encoding URL's, but maybe it is?

Yes it is I debugged and took sometime to understand the groovy part. So I see the code is actually splitting the path using "/" and then encoding the each string and thats why the $ is getting encoded.
Is there is plan to fix this?

It sounds like something that ought to be fixed. And now that you've digged into the code already it would be great if you could help out with a pull request :)

there is a work-around with RequestSpecBuilder:
RequestSpecification spec = new RequestSpecBuilder().setUrlEncodingEnabled(false); spec.setBaseUri(...);
Then it won't escape the $ character.

Was this page helpful?
0 / 5 - 0 ratings