Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Template Expression naming restrictions #1139

Merged
merged 1 commit into from
Dec 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 14 additions & 5 deletions core/src/main/java/feign/template/Expressions.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public final class Expressions {
*
* see https://tools.ietf.org/html/rfc6570#section-2.3 for more information.
*/
expressions.put(Pattern.compile("(\\w[-\\w.\\[\\]]*[ ]*)(:(.+))?"),

expressions.put(Pattern.compile("^([+#./;?&]?)(.*)$"),
SimpleExpression.class);
}

Expand Down Expand Up @@ -70,10 +71,18 @@ public static Expression create(final String value, final FragmentType type) {
Matcher matcher = expressionPattern.matcher(expression);
if (matcher.matches()) {
/* we have a valid variable expression, extract the name from the first group */
variableName = matcher.group(1).trim();
if (matcher.group(2) != null && matcher.group(3) != null) {
/* this variable contains an optional pattern */
variablePattern = matcher.group(3);
variableName = matcher.group(2).trim();
if (variableName.contains(":")) {
/* split on the colon */
String[] parts = variableName.split(":");
variableName = parts[0];
variablePattern = parts[1];
}

/* look for nested expressions */
if (variableName.contains("{")) {
/* nested, literal */
return null;
}
}

Expand Down
11 changes: 11 additions & 0 deletions core/src/test/java/feign/template/QueryTemplateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,15 @@ public void expandCollectionValueWithBrackets() {
/* brackets will be pct-encoded */
assertThat(expanded).isEqualToIgnoringCase("collection%5B%5D=1,2");
}

@Test
public void expandCollectionValueWithDollar() {
QueryTemplate template =
QueryTemplate.create("$collection", Collections.singletonList("{$collection}"),
Util.UTF_8, CollectionFormat.CSV);
String expanded = template.expand(Collections.singletonMap("$collection",
Arrays.asList("1", "2")));
/* brackets will be pct-encoded */
assertThat(expanded).isEqualToIgnoringCase("$collection=1,2");
}
}