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:
Oliver Gierke
2014-05-05 14:09:38 +02:00
parent ef7cf82441
commit fe3c10bead
2 changed files with 12 additions and 0 deletions

View File

@@ -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()) {

View File

@@ -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"));
}
}