#56 - LinkBuilderSupport.slash(…) now handles fragments correctly.
This commit is contained in:
@@ -62,6 +62,10 @@ public abstract class LinkBuilderSupport<T extends LinkBuilder> implements LinkB
|
||||
|
||||
String path = object.toString();
|
||||
|
||||
if (path.endsWith("#")) {
|
||||
path = path.substring(0, path.length() - 1);
|
||||
}
|
||||
|
||||
if (!StringUtils.hasText(path)) {
|
||||
return getThis();
|
||||
}
|
||||
@@ -73,6 +77,11 @@ public abstract class LinkBuilderSupport<T extends LinkBuilder> implements LinkB
|
||||
builder.pathSegment(pathSegment);
|
||||
}
|
||||
|
||||
String fragment = components.getFragment();
|
||||
if (StringUtils.hasText(fragment)) {
|
||||
builder.fragment(fragment);
|
||||
}
|
||||
|
||||
return createNewInstance(builder.query(components.getQuery()));
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,20 @@ public class LinkBuilderSupportUnitTest extends TestUtils {
|
||||
assertThat(builder.slash(""), is(builder));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void appendsFragmentCorrectly() {
|
||||
|
||||
SampleLinkBuilder builder = new SampleLinkBuilder(UriComponentsBuilder.newInstance());
|
||||
builder = builder.slash("foo#bar");
|
||||
assertThat(builder.toString(), endsWith("foo#bar"));
|
||||
builder = builder.slash("bar");
|
||||
assertThat(builder.toString(), endsWith("foo/bar#bar"));
|
||||
builder = builder.slash("#foo");
|
||||
assertThat(builder.toString(), endsWith("foo/bar#foo"));
|
||||
builder = builder.slash("#");
|
||||
assertThat(builder.toString(), endsWith("foo/bar#foo"));
|
||||
}
|
||||
|
||||
static class SampleLinkBuilder extends LinkBuilderSupport<SampleLinkBuilder> {
|
||||
|
||||
public SampleLinkBuilder(UriComponentsBuilder builder) {
|
||||
|
||||
Reference in New Issue
Block a user