Re: URI Escaping and Unescaping

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 21 Jun 2007 10:39:01 +0200

Bill de hOra wrote:
> Marc Hadley wrote:
>> My working assumption, which isn't reflected in the Javadoc, is that
>> the developer would work with unescaped values for @UriParam,
>> @QueryParam and @MatrixParam so the value of name would be "x y".
> Mine too.

Mine too, and they would be unescaped using UTF-8 [1].

>> A related question is whether the @UriTemplate value should be in
>> escaped or unescaped form. In this case I'd say that it should be in
>> escaped form, i.e. a developer would have to write
>> @UriTemplate("hello%20world") rather than @UriTemplate("hello world").
> That would make the API asymmetric/inconsistent...?

FWIW I notice that Firefox lets one type in a URI path "/hello world"
and it translates it to "/hello%20world".

Note that the @UriTemplate as currently used only deals with paths
(relative to the base URI).

There is another potential inconsistency in the following: what should
the UriInfo.getURIPath() [2] return, escaped or unescaped characters?

The reason being that:

   info.getBaseURI().resolve(info.getURIPath()) [3]

would result in an error if the path is not escaped, but it is a very
convenient thing to use (and it is easy to forget, like me, to do
URLEncoder.encode(info.getURIPath(), "UTF-8"). In servlet the
HttpServletRequest.getPathInfo() is decoded (as per the CGI PATH_INFO
variable), as is URI.getPath().

Dealing with URIs and paths with is not easy... IMHO we
need some good classes/methods to create URIs from templates, decoded
paths (relative to the base URI) for embedding in content. I like RoR
way of managing URIs. I wonder what we could provide something that
tools can build upon to provide typed URIs?



| ? + ? = To question
    Paul Sandoz