Permalink
Browse files

path params - allow underscores in path param names

This fixes #170
  • Loading branch information...
fcamblor committed Aug 24, 2017
1 parent 6a56329 commit 4c139a7327c415d4e5e0aa80a303248df4702b83
@@ -112,6 +112,11 @@ void parse() {
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;
@@ -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",
@@ -188,7 +193,7 @@ public void end(PathPatternParser pathPatternParser) {
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());
@@ -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")

0 comments on commit 4c139a7

Please sign in to comment.