#582 - LinkBuilder now makes sure appended path is considered path segment.
We now prepend the given path (and query) handed to LinkBuilderSupport.slash(…) to make sure calls to UriComponentsBuilder.fromUriString(…) always considers the given value as path. Previously, a value containing a colon caused problems as the regex to detect scheme and port would accidentally match. Related ticket: https://jira.spring.io/browse/DATAREST-1074
This commit is contained in:
@@ -86,6 +86,8 @@ public abstract class LinkBuilderSupport<T extends LinkBuilder> implements LinkB
|
||||
return getThis();
|
||||
}
|
||||
|
||||
path = path.startsWith("/") ? path : "/".concat(path);
|
||||
|
||||
return slash(UriComponentsBuilder.fromUriString(path).build(), false);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,19 @@ public class LinkBuilderSupportUnitTest extends TestUtils {
|
||||
assertThat(builder.toString(), endsWith("foo%20bar#foo"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #582
|
||||
*/
|
||||
@Test
|
||||
public void appendsPathContainingColonsCorrectly() {
|
||||
|
||||
SampleLinkBuilder builder = new SampleLinkBuilder(UriComponentsBuilder.newInstance());
|
||||
|
||||
builder = builder.slash("47:11");
|
||||
|
||||
assertThat(builder.toString(), endsWith("47:11"));
|
||||
}
|
||||
|
||||
static class SampleLinkBuilder extends LinkBuilderSupport<SampleLinkBuilder> {
|
||||
|
||||
public SampleLinkBuilder(UriComponentsBuilder builder) {
|
||||
|
||||
@@ -397,7 +397,7 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
|
||||
* @see #192
|
||||
*/
|
||||
@Test
|
||||
public void usesRootMappingOfTargetClassForMethodsOfParen() throws Exception {
|
||||
public void usesRootMappingOfTargetClassForMethodsOfParent() throws Exception {
|
||||
|
||||
Method method = ParentControllerWithoutRootMapping.class.getMethod("someEmptyMappedMethod");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user