Skip to content

Commit

Permalink
path params - allow underscores in path param names
Browse files Browse the repository at this point in the history
This fixes #170
  • Loading branch information
fcamblor committed Aug 24, 2017
1 parent 6a56329 commit 4c139a7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 8 additions & 3 deletions restx-core/src/main/java/restx/StdRestxRequestMatcher.java
Expand Up @@ -112,6 +112,11 @@ private static interface PathParserCharProcessor {
void end(PathPatternParser pathPatternParser);
}

private static boolean isValidPathParamNameChar(int curChar) {
//only letters/digit/underscore are authorized in path param name
return Character.isLetterOrDigit(curChar) || curChar == '_';
}

private static final class CurlyBracesPathParamPathParserCharProcessor implements PathParserCharProcessor {
private int openBr = 1;
private boolean inRegexDef;
Expand Down Expand Up @@ -166,8 +171,8 @@ public void handle(int curChar, PathPatternParser pathPatternParser) {
inRegexDef = true;
pathParamRegex.append("(");
} else {
if (!Character.isLetterOrDigit(curChar)) {
//only letters are authorized in path param name
if (!isValidPathParamNameChar(curChar)) {
//only letters/digit/underscore are authorized in path param name
throw new IllegalArgumentException(String.format(
"illegal path parameter definition '%s' at offset %d" +
" - only letters and digits are authorized in path param name",
Expand All @@ -188,7 +193,7 @@ private static final class SimpleColumnBasedPathParamParserCharProcessor impleme
private StringBuilder pathParamName = new StringBuilder();
@Override
public void handle(int curChar, PathPatternParser pathPatternParser) {
if (!Character.isLetterOrDigit(curChar)) {
if (!isValidPathParamNameChar(curChar)) {
pathPatternParser.patternBuilder.append("([^\\/]+)");
pathPatternParser.stdPathPatternBuilder.append("{").append(pathParamName).append("}");
pathPatternParser.groupNamesBuilder.add(pathParamName.toString());
Expand Down
Expand Up @@ -46,9 +46,9 @@ public void setVal(String val) {
}
}

@GET("/params/path/{a}/:b/{c:\\d+}:d")
public String pathparams(String a, String b, String c, String d) {
return "a=" + a + " b=" + b + " c=" + c + " d=" + d;
@GET("/params/path/{a}/:_b/{c:\\d+}:d")
public String pathparams(String a, String _b, String c, String d) {
return "a=" + a + " b=" + _b + " c=" + c + " d=" + d;
}

@GET("/params/query/withOptionalString")
Expand Down

0 comments on commit 4c139a7

Please sign in to comment.