users@jsr311.java.net

Re: JAX-RS: escaping UriBuilder query params

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Wed, 23 Jul 2008 09:37:26 -0400

Sounds good to me.

Marc.

On Jul 22, 2008, at 11:04 PM, Manger, James H wrote:

> I suggest renaming
> UriBuilder replaceQueryParams(String query);
> to
> UriBuilder replaceQuery(String query);
> or (better still) to
> UriBuilder query(String query);
>
>
> It seems trivial but it is sort of important as query parameters
> need different %-escaping than a whole query.
>
> queryParam(String name, Object… values) should %-escape ‘=’ and ‘&’
> in the name, and ‘&’ in the values (and similarly for any referenced
> placeholder variable values). replaceQueryParam(String, Object…)
> should behave the same.
>
> replaceQueryParams(String), however, should not %-escape ‘=’ or ‘&”
> in its argument or (it follows) in placeholder variable values it
> references.
>
> For instance,
>
> UriBuilder.fromPath(“search”).replaceQueryParam(“q”,
> “{term}”).build(“Jack&Jill=water”)
> -> “search?q=Jack%26Jill%3Dwater”
>
>
> UriBuilder
> .fromPath
> (“search”).replaceQueryParams(“q={term}”).build(“Jack&Jill=water”)
> -> “search?q=Jack&Jill=water”
>
> Removing “Params” from the latter gives some hint that it is not
> equivalent to the former, in that it will not be careful to preserve
> any parameter structure.
>
>
> UriBuilder
> .fromPath(“search”).query(“q={term}”).build(“Jack&Jill=water”)
> -> “search?q=Jack&Jill=water”
>
> James Manger
>

---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.