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.
This commit is contained in:
@@ -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()) {
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user