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.
This commit is contained in:
Oliver Gierke
2015-09-10 09:17:11 +02:00
parent 0704f33a6c
commit 465bcdc689
2 changed files with 14 additions and 1 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -111,7 +111,11 @@ public class BaseUri {
Assert.notNull(lookupPath, "Lookup path must not be null!");
// Temporary fix for SPR-13455
lookupPath = lookupPath.replaceAll("//", "/");
lookupPath = lookupPath.contains("{") ? lookupPath.substring(0, lookupPath.indexOf('{')) : lookupPath;
lookupPath = trimTrailingCharacter(lookupPath, '/');
if (!baseUri.isAbsolute()) {

View File

@@ -111,4 +111,13 @@ public class BaseUriUnitTests {
ServletWebRequest request = new ServletWebRequest(new MockHttpServletRequest("GET", "/foo/bar{?projection}"));
assertThat(uri.getRepositoryLookupPath(request), is("/bar"));
}
/**
* @see DATAREST-674
* @see SPR-13455
*/
@Test
public void repositoryLookupPathHandlesDoubleSlashes() {
assertThat(BaseUri.NONE.getRepositoryLookupPath("/books//1"), is("/books/1"));
}
}