users@jersey.java.net

[Jersey] Handling parameters with unicode encoding

From: <tpp+jersey_at_iki.fi>
Date: Tue, 11 Jun 2013 18:00:54 +0000 (UTC)

I just ran into an issue with how Jersey decodes unicode String
parameters.

Let's say I have a method in my resource like this:

@GET
@Path("/foo/{bar}")
public String getFoo(@PathParam("bar") String bar) {
  ...
}

A client sends in two requests:

/foo/%C3%A1
/foo/a%CC%81

Both these decode to:

/foo/á

That's not quite true, however. The internal representation of bar is:

[á]
[a, ́]

and hence the Strings aren't equal.

I can fix this by normalizing bar in the getFoo() method or with a
ContainerRequestFilter with:

bar = java.text.Normalizer.normalize(bar, Form.NFC);

But that seems kinda stupid to do on every String parameter on every
method.

Is this something Jersey could (or should) handle when it's processing
request parameters?

I'm using 1.17 at the moment. I do not know if 2.0 behaves differently.

-TPP