When you are configuring a route with a regex, now you can set a path parameter name with group names inside regex (only group names alphanumeric accepted) or with groups names array (it matches in order)
package io.vertx.ext.web.impl;
+import io.netty.handler.codec.http.QueryStringDecoder;
import io.vertx.core.Handler;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.HttpServerRequest;
@@ -24,16 +25,14 @@ import io.vertx.core.logging.LoggerFactory;
import io.vertx.ext.web.MIMEHeader;
import io.vertx.ext.web.Route;
import io.vertx.ext.web.RoutingContext;
-import io.netty.handler.codec.http.QueryStringDecoder;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
- *
* This class is thread-safe
- *
+ * <p>
* Some parts (e.g. content negotiation) from Yoke by Paulo Lopes
*
* @author <a href="http://tfox.org">Tim Fox</a>
@@ -256,7 +255,13 @@ public class RouteImpl implements Route {
// decode the path as it could contain escaped chars.
for (int i = 0; i < groups.size(); i++) {
final String k = groups.get(i);
- final String value = Utils.urlDecode(m.group("p" + i), false);
+ String undecodedValue;
+ try {
+ undecodedValue = m.group("p" + i);
+ } catch (IllegalArgumentException e) {
+ undecodedValue = m.group(k);
+ }
+ final String value = Utils.urlDecode(undecodedValue, false);
if (!request.params().contains(k)) {
params.put(k, value);
} else {
@@ -375,7 +380,12 @@ public class RouteImpl implements Route {
}
}
+ public void setRegexGroupsNames(List<String> groups) {
+ this.groups = groups;
+ }
+
private void setRegex(String regex) {
+ // Check if there are any groups with names
pattern = Pattern.compile(regex);
}
