Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uribuilder encoding with exclamation mark

I'm trying to use Uribuilder from:

javax.ws.rs.core.UriBuilder;

To update a URI. The issue is that the parameter name gets escaped when I use replaceQueryParam.

so:

UriBuilder uriBuilder = webResource.getUriBuilder().
            replaceQueryParam("abcd!dcv, "wid").
            replaceQueryParam("format", "json");

if there is already an existing "abcd!dcv" parameter in the Uribuilder, it will escape and add a new one. so it will become

?abcd!dcv=originalvalue&abcd%21cdv=wid

instead of

?abcd!dcv=wid

How should I get around this? Thanks!

like image 823
Raymond Array Wang Avatar asked Nov 21 '25 00:11

Raymond Array Wang


1 Answers

URIBuilder is an abstract class and the implementation gets to decide which characters need special encoding and which do not. The URIBuilder we get from a WebResource is attempting to follow the guidelines of RFC 3986. On page 12, ! is listed as a sub-delimiter and this is why it is getting encoded. From my reading of the RFC, I don't think we should be using ! as part of a query parameter. For instance, Vaading uses ! to distinguish between sub-windows of the same application.

The simplest work around I can think of is to simply not use URIBuilder or use the fromURI method that takes a String as input. You can create the URI with everything except the part with the characters we don't want encoded, convert this to astring, manipulate astring to replace the query parameter and then call URIBuilder.fromURI(aString)

like image 187
Thorn Avatar answered Nov 23 '25 14:11

Thorn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!