summaryrefslogtreecommitdiffstats
path: root/vespaclient-container-plugin
diff options
context:
space:
mode:
authorvalerijf <valerijf@yahoo-inc.com>2017-06-06 13:13:12 +0200
committervalerijf <valerijf@yahoo-inc.com>2017-06-06 13:13:12 +0200
commit7c0493e88f25b486acbc34eb86fd6486a38c84d5 (patch)
treed2f9ff5d805deb33cc41a57de834ffb0c6c90485 /vespaclient-container-plugin
parent77e38e9b883580382e555bdba3c553883bc3f72b (diff)
Url decode groupname in document/v1
Diffstat (limited to 'vespaclient-container-plugin')
-rw-r--r--vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/RestUri.java12
-rw-r--r--vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/RestUriTest.java10
2 files changed, 19 insertions, 3 deletions
diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/RestUri.java b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/RestUri.java
index 7b6bc4e87c5..26c66085437 100644
--- a/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/RestUri.java
+++ b/vespaclient-container-plugin/src/main/java/com/yahoo/document/restapi/RestUri.java
@@ -105,13 +105,18 @@ public class RestUri {
if (readPos >= rawParts.size()) {
throwUsage(originalPath);
}
- return rawParts.get(readPos++);
+ String nextToken = rawParts.get(readPos++);
+ return urlDecodeOrException(nextToken);
}
String restOfPath() throws RestApiException {
String rawId = Joiner.on("/").join(rawParts.listIterator(readPos));
+ return urlDecodeOrException(rawId);
+ }
+
+ String urlDecodeOrException(String url) throws RestApiException {
try {
- return URLDecoder.decode(rawId, StandardCharsets.UTF_8.name());
+ return URLDecoder.decode(url, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
throw new RestApiException(Response.createErrorResponse(BAD_REQUEST,"Problems decoding the URI: " + e.getMessage(), apiErrorCodes.ERROR_ID_DECODING_PATH));
}
@@ -132,7 +137,8 @@ public class RestUri {
case "number":
group = Optional.of(new Group(NUMBER_STREAMING, pathParser.nextTokenOrException()));
break;
- case "docid": group = Optional.empty();
+ case "docid":
+ group = Optional.empty();
break;
case "group":
group = Optional.of(new Group(GROUP_STREAMING, pathParser.nextTokenOrException()));
diff --git a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/RestUriTest.java b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/RestUriTest.java
index b2a8200b4e1..5dc0cef9e1a 100644
--- a/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/RestUriTest.java
+++ b/vespaclient-container-plugin/src/test/java/com/yahoo/document/restapi/RestUriTest.java
@@ -94,6 +94,16 @@ public class RestUriTest {
}
@Test
+ public void testGroupUrlDecode() throws Exception {
+ RestUri restUri = new RestUri(createUri("/document/v1/namespace/doctype/group/group#123/myid", ""));
+ assertThat(restUri.getDocId(), is("myid"));
+ assertThat(restUri.getDocumentType(), is("doctype"));
+ assertThat(restUri.getGroup().get().name, is('g'));
+ assertThat(restUri.getGroup().get().value, is("group#123"));
+ assertThat(restUri.generateFullId(), is("id:namespace:doctype:g=group#123:myid"));
+ }
+
+ @Test
public void testGroupN() throws Exception {
RestUri restUri = new RestUri(createUri("/document/v1/namespace/doctype/number/group/myid", ""));
assertThat(restUri.getGroup().get().name, is('n'));