$ is not being escaped in a URL Variable

AdriaM
Mega Sage

Hi everyone,

We have the following endpoint

https://<endpoint>/action?pack=${pack}

Where we need that

${pack}=AA%24123456

Where %24 is the "Percent Escaping" of $ character

 

If we use RESTMessageV2.setStringParameter(AA$123456), then we get:

https://<endpoint>/action?pack=AA$123456 ($ is not escaped)

 

If we use RESTMessageV2.setStringParameterNoEscape(AA%24123456), then we get:

https://<endpoint>/action?pack=AA%24123456 (Parameter is not escaped - OK)

but on the Outbound Http message we see:

https://<endpoint>/action?pack=AA%2524123456 (where %25 is the Percent Escaping of the "%" character)

 

If we use RESTMessageV2.setStringParameterNoEscape(AA&percnt;24123456) where "&percnt;" is HTML name of % character, then we get:

https://<endpoint>/action?pack=AA&percnt;24123456 (Parameter is not escaped - OK)

but we get and 405 error of the remote that pack id is not well formed.

 

Is there a way of sending $ dollar character Percent Escaped as %24 on the URL of an endpoint?

3 REPLIES 3

Maik Skoddow
Tera Patron
Tera Patron

Try to encode the value first with GlideStringUtil.urlEncode() before passing it to one of the two setStringParameter methods 

ChrisBurks
Mega Sage

Hi @AdriaM ,

 

According to the documentation the escaping pertains to XML reserved characters for the purposed of values that might be used within XML. It's a little different than URL encoding. So using the .setStringParameterNoEscape() method with the normal value including the dollar sign should work because it won't escape XML reserved characters but will encode the URL.

.setStringParameterNoEscape("pack", "AA$123456");

 

This should result in the correct URL encoding of
https://<endpoint>/action?pack=AA%24123456  

 

 I made an example using the rest message to make a search on google. You can see in the screenshot that the parameter value was encoded correctly.

search_request_example.png

 

 

 

Either of the solution works:

 

If I use GlideStringUtil.urlEncode() it encodes % as %25 so It is finally sending AA%2524123456

On the other hand If I send AA$123456 this not enconding the $, so is sending "AA$123456".

 

What I've seen on the tests is that If I send the message without Mid Server the message is correctly sended "AA%24123456".

If I use the mid-server is when the problem arises. It is sending "AA%2524123456"

 

Exists a parameter on the Mid-Server (or http header maybe) not to "Percent Encoding" what is sended from the Instance? I've reviewed all the available parameters and I've not found any.