users@jersey.java.net

[Jersey] Inconsistent encoding of slashes etc. in UriBuilder.path() and .segment()

From: Klaus Brunner <klaus.brunner_at_gmail.com>
Date: Wed, 5 Jun 2013 16:02:39 +0200

According to https://java.net/jira/browse/JAX_RS_SPEC-70, the following snippet

UriBuilder.fromPath("{arg1}").segment("{arg1}").build("foo/bar");

should resolve to "foo/bar/foo%2Fbar" (quoting the JIRA issue: "if it
doesn't it's already a bug in the implementation").

Using Jersey 1.17.1, it resolves to "foo/bar/foo/bar".

Using Jersey 2.0, it resolves to "foo%2Fbar/foo%2Fbar".

Using Jersey 2.0 and .build("foo/bar", false), it also resolves to
"foo%2Fbar/foo%2Fbar".

(Tiny test project at https://github.com/KlausBrunner/uribuildertest )

A semicolon is also always either not encoded (1.17.1) or encoded
(2.0) to percent notation.

Frankly, the spec is so weird on this (as the original explanation in
JAX_RS_SPEC-70 eloquently explains) that I'm not sure where the bug
is. (For one, I don't understand why only forward slashes should get
special treatment...) However, I would at least expect that 1.x would
treat the slashes (and semicolons) in segments differently than in
path elements, so I'm inclined to think this is at least a bug in
1.17.1 and probably also in 2.0 (there should at least be some
difference whether the encodeSlashInPath flag is set or not).

Or am I seriously misunderstanding something?

Klaus