Repository navigation
Require a scheme separator for absolute URIs - #3721
Conversation
`UriUtils.isAbsolute` only checked for an `http` prefix, so a relative uri such as `httpbin/get` was rejected as absolute and `httpbin.org` was accepted as a target. It now requires `http://` or `https://`.
utafrali
left a comment
There was a problem hiding this comment.
The fix is correct: requiring :// after the scheme eliminates both false positives (httpbin.org accepted as absolute) and false negatives (httpbin/get rejected as absolute). The two minor points are test-convention issues, not correctness problems, so the PR is approvable as-is.
| .isThrownBy(() -> new RequestTemplate().target("httpbin.org")) | ||
| .withMessage("target values must be absolute."); | ||
| } | ||
|
|
There was a problem hiding this comment.
The for loop over schemes means a single test failure won't tell you which variant broke. The project already uses @ParameterizedTest + @MethodSource for data-driven cases elsewhere; that pattern would be more consistent here and give a clearer failure message per scheme:
@ParameterizedTest
@ValueSource(strings = {"HTTP", "HTTPS", "hTtP", "hTtPs"})
void rejectsAbsoluteUriWithCaseInsensitiveScheme(String scheme) {
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> new RequestTemplate().uri(scheme + "://example.com/path"))
.withMessage("url values must be not be absolute.");
}| @@ -128,6 +128,24 @@ void canInsertAbsoluteHrefWithCaseInsensitiveScheme() { | |||
| } | |||
| } | |||
There was a problem hiding this comment.
These integration-level tests are useful, but UriUtils.isAbsolute is a pure utility method and UriUtilsTest.java is the natural home for direct unit tests of it. Adding a few cases there (e.g. httpbin/get returns false, httpbin.org returns false, HTTP://X returns true) would make the unit contract explicit and easier to find when the method changes in the future.
Each scheme is now reported on its own, and UriUtils#isAbsolute has direct tests next to the other UriUtils cases.
UriUtils.isAbsoluteonly checks for anhttpprefix, so a relative uri such as@RequestLine("GET httpbin/get")or a JAX-RS@Path("httproutes")is rejected with "url values must be not be absolute.", andhttpbin.orgis accepted as a target. It now requireshttp://orhttps://, still without regard to case.