1818import java .util .stream .Stream ;
1919
2020/**
21- * Sync: 20-01-20
22- * Commit: 17fb1065d2b256d20f68bed0b7bca6c2942aff49
21+ * Sync: May 22, 2020
22+ * Commit: 5704d7ee98edd3fe55169b506531bdd061667c70
2323 */
2424class Chi implements RouteTree {
2525 private static final String EMPTY_STRING = "" ;
@@ -320,7 +320,7 @@ Node addChild(Node child, String search) {
320320
321321 if (segTyp == ntRegexp ) {
322322 child .prefix = seg .rexPat ;
323- child .rex = Pattern .compile (seg .rexPat . toString () );
323+ child .rex = Pattern .compile (seg .rexPat );
324324 }
325325
326326 if (segStartIdx == 0 ) {
@@ -471,7 +471,7 @@ Route findRoute(RouterMatch rctx, String method, String path) {
471471 }
472472
473473 if (ntyp == ntRegexp && xn .rex != null ) {
474- if (!xn .rex .matcher (xsearch .substring (0 , p ). toString () ).matches ()) {
474+ if (!xn .rex .matcher (xsearch .substring (0 , p )).matches ()) {
475475 continue ;
476476 }
477477 } else if (xsearch .substring (0 , p ).indexOf ('/' ) != -1 ) {
@@ -480,12 +480,32 @@ Route findRoute(RouterMatch rctx, String method, String path) {
480480 }
481481
482482 // rctx.routeParams.Values = append(rctx.routeParams.Values, xsearch[:p])
483+ int prevlen = rctx .vars .size ();
483484 rctx .value (xsearch .substring (0 , p ));
484485 xsearch = xsearch .substring (p );
485- break ;
486+
487+ if (xsearch .length () == 0 ) {
488+ if (xn .isLeaf ()) {
489+ Route h = xn .endpoints .get (method );
490+ if (h != null ) {
491+ rctx .key (h .getPathKeys ());
492+ return h ;
493+ }
494+ rctx .methodNotAllowed (xn .endpoints .keySet ());
495+ }
496+ }
497+
498+ // recursively find the next node on this branch
499+ Route fin = xn .findRoute (rctx , method , xsearch );
500+ if (fin != null ) {
501+ return fin ;
502+ }
503+
504+ // not found on this branch, reset vars
505+ rctx .truncate (prevlen );
506+ xsearch = path ;
486507 }
487508 break ;
488-
489509 default :
490510 // catch-all nodes
491511 // rctx.routeParams.Values = append(rctx.routeParams.Values, search)
@@ -649,7 +669,7 @@ Segment patNextSegment(String pattern) {
649669 int idx = key .indexOf (':' );
650670 if (idx >= 0 ) {
651671 nt = ntRegexp ;
652- rexpat = key .substring (idx + 1 ). toString () ;
672+ rexpat = key .substring (idx + 1 );
653673 // key = key.substring(0, idx);
654674 }
655675
0 commit comments