Skip to content

Commit

Permalink
Merge pull request #55 from kevinstembridge/master
Browse files Browse the repository at this point in the history
Issue #54: An encoded slash in a path parameter is treated as a path …
  • Loading branch information
danielbodart authored Dec 18, 2017
2 parents d7207f7 + e3c5b14 commit 4a70774
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/com/googlecode/utterlyidle/UriTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.List;
import java.util.regex.MatchResult;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static com.googlecode.totallylazy.regex.Regex.regex;
import static com.googlecode.utterlyidle.PathParameters.pathParameters;
Expand Down Expand Up @@ -44,7 +45,10 @@ public boolean matches(final String uri) {
}

public PathParameters extract(String uri) {
List<String> values = groupValues(templateRegex.findMatches(UrlEncodedMessage.decode(trimSlashes(uri))).head());
List<String> values = groupValues(templateRegex.findMatches(trimSlashes(uri)).head())
.stream()
.map(UrlEncodedMessage::decode)
.collect(Collectors.toList());
return pathParameters(names.zip(values));
}

Expand Down
8 changes: 8 additions & 0 deletions test/com/googlecode/utterlyidle/UriTemplateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ public void canExtractFromUriWithEncodedSpace() {
assertThat(template.extract("path/foo+bar").getValue("id1"), is("foo bar"));
}

@Test
public void canExtractFromUriWithEncodedSlash() {
UriTemplate template = uriTemplate("path/{id1}");
PathParameters pathParameters = template.extract("path/foo%2Fbar");
String id1 = pathParameters.getValue("id1");
assertThat(id1, is("foo/bar"));
}

@Test
public void canGenerateUri() {
UriTemplate template = uriTemplate("path/{id}");
Expand Down

0 comments on commit 4a70774

Please sign in to comment.