0

javax.ws.rs.core.UriBuilder is not escaping } correctly:

import javax.ws.rs.core.UriBuilder;
public void test() {
    final UriBuilder builder = UriBuilder.fromUri("http://host");
    builder.path("dir}one");
    l.info(builder.toString());
}

Will output http://host/dir}one, leaving } unescaped.

Whereas org.apache.http.client.utils.URIBuilder:

org.apache.http.client.utils.URIBuilder;
public void testApache() {
    final URIBuilder builder = new URIBuilder(URI.create("http://host"));
    builder.setPath("dir}one");
    l.info(builder.toString());
}

Will output http://hostdir%7Done, escaping } with %7D as expected.

Is this a bug in the javax.ws.rs.core.UriBuilder?

Roland
  • 7,028
  • 12
  • 58
  • 109

1 Answers1

1

According to RFC 3986 the character } is not a reserved character and therefore it need not be escaped. It can be escaped with %7D, but that is not necessary.

So both UriBuilder implementations behave correctly.

Community
  • 1
  • 1
P.J.Meisch
  • 15,266
  • 6
  • 44
  • 60
  • If you go throught the answers of this [question](https://stackoverflow.com/questions/1547899/which-characters-make-a-url-invalid) you see mentions of `}` as either unwise character or forbidden. There is no clear consensus, but it still seems that the wiser choice is to escape it. – Roland Jul 18 '17 at 07:29
  • 1
    wiser indeed, especially when thinking about programs processing such an URI. I would prefer to encode it as well, but it is no error to not encode it, so actually your code should be able to handle such characters unencoded – P.J.Meisch Jul 18 '17 at 07:54