Why doesn't UriInfo.getQueryParameters() decode '+'?

怎甘沉沦 提交于 2019-12-24 04:06:13

问题


I know I can work around this, but it seems very strange that the behaviour is different if you use an annotated query parameter, compared with pulling the parameter out of the parameter map (which should be decoded according to the javadoc). Is this a bug, or just a quirk?

@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
public Response getAssets(@Context UriInfo info, @QueryParam("q") String searchQuery) {

    // The request URI is http://myhost.com/appRoot?q=foo+bar%20baz
    // At this point seachQuery="foo bar baz"
    // The + has been decoded (along with any % encoded characters)

    // Here searchQuery2="foo+bar baz", the '+' has not been decoded
    // but the %20 has been
    MultivaluedMap<String, String> params = info.getQueryParameters();
    String searchQuery2 = params.get("q").get(0);

回答1:


According to the Javadocs for UrlInfo.getQueryParameters only "sequences of escaped octets in parameter names and values are decoded".

On the other hand, QueryParam Javadocs states that "Values are URL decoded unless this is disabled using the Encoded annotation".

So, answering your question, it looks like a specification decision.

Anyway, maybe you should bring up that discussion on JAX-RS mailing lists.



来源:https://stackoverflow.com/questions/29824160/why-doesnt-uriinfo-getqueryparameters-decode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!