users@jsr311.java.net

Re: UriBuilder.buildFromEncoded() spec interpretation

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Mon, 26 Jan 2009 09:28:06 -0500

On Jan 24, 2009, at 7:04 AM, Andrzej Michalec wrote:
> I am looking for clarification of JAX-RS specification 1.0 for
> "UriBuilder.build(Object... values)" in encoding context.
> Spec says that "All '%' characters in the stringified values will be
> encoded." This note matches behavior or URLEncoder, since % must be
> encoded anyway.
> My problem is that for "UriBuilder.buildFromEncoded(Object... values)"
> spec says "All % characters in the stringified values that are not
> followed by two hexadecimal numbers will be encoded".
>
> My interpretation of spec authors' intention is that: passed values
> are already encoded e.g. non-encoded value "foo%bar" must be encoded
> to "foo%25bar" and passed here. However if there are any '%' not
> matching percent-with-two-hexes like second '%' in "foo%25bar%baz".
> Their encoding should be forced. I think then "foo%25bar%baz" should
> become "foo%25bar%25baz".

Yes, that is the correct interpretation.


> If URLEncoder would be applied once more
> result would be different, both percent chars would be affected
> leading to "foo%2525bar%25baz".
>
> How should "buildFromEncoded()" behave when "foo+bar" is passed? If
> '%' char encoding is forced also '+' char should be, leading to
> "foo%2Bbar".
>
buildFromEncoded treats all characters other than '%' the same as
build. I.e. they are encoded if they are not allowed in the
corresponding URI component.

> I see behavior of "buildFromEncoded" as not aligned with URLEncode
> behavior. This "extra" safety rule is not necessary for me... can
> anybody explain this aspect?
>
Its possible to obtain encoded values from the JAX-RS APIs, the
buildFromEncoded method is present to allow use of such values without
the need to decode or worry about double encoding of '%' chars.

Marc.

> cheers,
> andy.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jsr311.dev.java.net
> For additional commands, e-mail: users-help_at_jsr311.dev.java.net
>

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