#26, #39 - Fixed potential transitive assertion error in UrComponentsBuilder.

If a String piped into LinkBuilderSupport.slash(…) is empty, the call to UriComponentsBuilder.fromUriString(…) fails with an assertion exception. We now guard against this specific case by returning the current builder instance in case an empty String (potentially returned from the toString() method of the object handed in) would be handed to the UriComponentsBuilder.

The issue was introduced by commit 84efebc7a6.
This commit is contained in:
Oliver Gierke
2013-03-04 15:59:22 +01:00
parent f568845146
commit 6bc906971a
2 changed files with 63 additions and 1 deletions

View File

@@ -21,6 +21,7 @@ import org.springframework.hateoas.Identifiable;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.LinkBuilder;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
@@ -59,7 +60,13 @@ public abstract class LinkBuilderSupport<T extends LinkBuilder> implements LinkB
return slash((Identifiable<?>) object);
}
UriComponents components = UriComponentsBuilder.fromUriString(object.toString()).build();
String path = object.toString();
if (!StringUtils.hasText(path)) {
return getThis();
}
UriComponents components = UriComponentsBuilder.fromUriString(path).build();
UriComponentsBuilder builder = UriComponentsBuilder.fromUri(uriComponents.toUri());
for (String pathSegment : components.getPathSegments()) {