From fe3c10bead52d24c7520167811cc698f8ca3cba5 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Mon, 5 May 2014 14:09:38 +0200 Subject: [PATCH] DATAREST-300 - BaseUri now removes URI template variables from lookup path. BaseUri now strips away the tail of a lookup path starting with {. An unencoded { must never appear in a URI but could accidentally be sent by a client forgetting to expand URI templates we return. --- .../org/springframework/data/rest/webmvc/BaseUri.java | 1 + .../data/rest/webmvc/BaseUriUnitTests.java | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/BaseUri.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/BaseUri.java index 58cfd4e05..53801c998 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/BaseUri.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/BaseUri.java @@ -103,6 +103,7 @@ public class BaseUri { Assert.notNull(lookupPath, "Lookup path must not be null!"); + lookupPath = lookupPath.contains("{") ? lookupPath.substring(0, lookupPath.indexOf('{')) : lookupPath; lookupPath = trimTrailingCharacter(lookupPath, '/'); if (!baseUri.isAbsolute()) { diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/BaseUriUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/BaseUriUnitTests.java index 5ec028625..606a54b1e 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/BaseUriUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/BaseUriUnitTests.java @@ -87,4 +87,15 @@ public class BaseUriUnitTests { assertThat(uri.getRepositoryLookupPath("/foo/people"), is("/people")); assertThat(uri.getRepositoryLookupPath("/foo/people/"), is("/people")); } + + /** + * @see DATAREST-300 + */ + @Test + public void stripsTemplatePlaceholders() { + + BaseUri uri = new BaseUri(URI.create("foo")); + + assertThat(uri.getRepositoryLookupPath("/foo/bar{?projection}"), is("/bar")); + } }