From 59beb1db1a597a43ca2df00ac314c38d9e1bd99d Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Thu, 12 Jun 2014 12:43:00 +0200 Subject: [PATCH] DATAREST-318 - BaseUri now correctly strips template variables from request. Bugfix in BaseUri to correctly strip template variables when the repository lookup path is obtained from a NativeWebRequest. --- .../data/rest/webmvc/BaseUri.java | 2 -- .../data/rest/webmvc/BaseUriUnitTests.java | 17 +++++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) 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 53801c998..0a3205653 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 @@ -23,7 +23,6 @@ import java.util.List; import javax.servlet.http.HttpServletRequest; -import org.springframework.hateoas.UriTemplate; import org.springframework.util.Assert; import org.springframework.util.StringUtils; import org.springframework.web.context.request.NativeWebRequest; @@ -87,7 +86,6 @@ public class BaseUri { private String getRepositoryLookupPath(HttpServletRequest request) { String lookupPath = URL_PATH_HELPER.getLookupPathForRequest(request); - lookupPath = new UriTemplate(lookupPath).expand().toString(); return getRepositoryLookupPath(lookupPath); } 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 606a54b1e..7bbae6fe9 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 @@ -21,6 +21,8 @@ import static org.junit.Assert.*; import java.net.URI; import org.junit.Test; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.web.context.request.ServletWebRequest; /** * Unit tests for {@link BaseUri}. @@ -92,10 +94,21 @@ public class BaseUriUnitTests { * @see DATAREST-300 */ @Test - public void stripsTemplatePlaceholders() { + public void stripsTemplateVariablesFromPath() { + + BaseUri uri = new BaseUri(URI.create("foo")); + assertThat(uri.getRepositoryLookupPath("/foo/bar{?projection}"), is("/bar")); + } + + /** + * @see DATAREST-318 + */ + @Test + public void stripsTemplateVariablesFromRequest() { BaseUri uri = new BaseUri(URI.create("foo")); - assertThat(uri.getRepositoryLookupPath("/foo/bar{?projection}"), is("/bar")); + ServletWebRequest request = new ServletWebRequest(new MockHttpServletRequest("GET", "/foo/bar{?projection}")); + assertThat(uri.getRepositoryLookupPath(request), is("/bar")); } }