eclipse-ee4j / eclipse-ee4j/jersey
Improper relativization of URIs
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
**tl;dr**: `org.glassfish.jersey.uri.UriTemplate` relativizes URIs wrongly: Relativizing `http://a/b/c/d/e` against base URI `http://a/b/c/d` should yield `d/e` and not `e`, which would mean `http://a/b/c/e` if resolved against said base URI.
URIs that do not end in a slash do not properly get relativized in `UriTemplate.relativize()`. This improper relativization is because Jersey uses the relativization of `java.net.URI`, which comes with bug [JDK-6523089](https://bugs.openjdk.java.net/browse/JDK-6523089) - open since 2007. Yet, as Jersey addresses some of the bugs in `java.net.URI`, see [line 325 seqq. of `UriTemplate`](https://github.com/eclipse-ee4j/jersey/blob/6510bb901d121b93e2b72789160beae23d2cca12/core-common/src/main/java/org/glassfish/jersey/uri/UriTemplate.java#L325). I was wondering if this bug of `java.net.URI` could also be addressed in `UriTemplate`, which would still be in line with the [remark in the test cases to not relativize some URIs](https://github.com/eclipse-ee4j/jersey/blob/6510bb901d121b93e2b72789160beae23d2cca12/core-common/src/test/java/org/glassfish/jersey/uri/UriTemplateTest.java#L123). Note that in the test cases, the [line that tests the faulty behaviour](https://github.com/eclipse-ee4j/jersey/blob/6510bb901d121b93e2b72789160beae23d2cca12/core-common/src/test/java/org/glassfish/jersey/uri/UriTemplateTest.java#L112) of `relativize` is wrong, the [counterpart assertion for `resolve`](https://github.com/eclipse-ee4j/jersey/blob/6510bb901d121b93e2b72789160beae23d2cca12/core-common/src/test/java/org/glassfish/jersey/uri/UriTemplateTest.java#L58) is correct. That is, [said line to tests the faulty behaviour](https://github.com/eclipse-ee4j/jersey/blob/6510bb901d121b93e2b72789160beae23d2cca12/core-common/src/test/java/org/glassfish/jersey/uri/UriTemplateTest.java#L112) should read:
```java
assertThat(UriTemplate.relativize(baseUri, URI.create("http://a/b/c/d/e")), equalTo(URI.create("d/e")));
```
Interestingly, said remark is followed by an [assertion](https://github.com/eclipse-ee4j/jersey/blob/6510bb901d121b93e2b72789160beae23d2cca12/core-common/src/test/java/org/glassfish/jersey/uri/UriTemplateTest.java#L128) that considers the wrongly re-resolved URI from my example at the top.
Contributor guide
Assessment
This issue has not been assessed yet.