javax UriBuilder无法正确转义'}'

时间:2017-07-17 08:00:48

标签: java url uri uribuilder javax.ws.rs

javax.ws.rs.core.UriBuilder未正确转发}

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

输出http://host/dir}one,保留}未转义。

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());
}

输出http://hostdir%7Done,按预期使用}转发%7D

这是javax.ws.rs.core.UriBuilder中的错误吗?

1 个答案:

答案 0 :(得分: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.