From 76380eb65087146c8e297bf03a50653c1669fd33 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Thu, 10 Sep 2015 09:17:11 +0200 Subject: [PATCH] DATAREST-674 - Defensively handle potential double slashes in lookup path. We now defensively replace all double slashes contained in the lookup path as Spring 4.2 might return such paths due to a regression in UrlPathHelper. This might occur if the original URL contains intermediate matrix parameters (e.g. /books/;test/1) whose removal now results in double slashes and thus the downstream repository metadata lookup to fail. Related tickets: SPR-13455. --- .../org/springframework/data/rest/webmvc/BaseUri.java | 3 +++ .../data/rest/webmvc/BaseUriUnitTests.java | 9 +++++++++ 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 f1cc177cc..bbdfce1b2 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 @@ -111,6 +111,9 @@ public class BaseUri { Assert.notNull(lookupPath, "Lookup path must not be null!"); + // Temporary fix for SPR-13455 + lookupPath = lookupPath.replaceAll("//", "/"); + 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 a8bbf6416..3fade4198 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,13 @@ public class BaseUriUnitTests { assertThat(uri.getRepositoryLookupPath("/foo/people"), is("/people")); assertThat(uri.getRepositoryLookupPath("/foo/people/"), is("/people")); } + + /** + * @see DATAREST-674 + * @see SPR-13455 + */ + @Test + public void repositoryLookupPathHandlesDoubleSlashes() { + assertThat(BaseUri.NONE.getRepositoryLookupPath("/books//1"), is("/books/1")); + } }