ctx.matchedPath now stores raw route rather than processed array
authorJustin Wind <justin.wind+git@gmail.com>
Wed, 19 Jul 2023 19:17:03 +0000 (12:17 -0700)
committerJustin Wind <justin.wind+git@gmail.com>
Wed, 19 Jul 2023 19:19:54 +0000 (12:19 -0700)
lib/router/index.js
test/lib/router.js

index f0d2d945a53909c327ab1661c54e83e9a6cfe097..1585065e14ce79b804cd6de967965951ab0d535a 100644 (file)
@@ -69,6 +69,12 @@ class Router {
     }
 
     routePath[kPathMethods] = {};
+
+    Object.defineProperty(routePath, 'path', {
+      enumerable: false,
+      value: rawPath,
+    });
+
     Object.freeze(routePath);
     return routePath;
   }
@@ -253,7 +259,7 @@ class Router {
     const { matchedPath, pathParams } = this._pathFind(pathParts);
     ctx.params = pathParams;
     if (matchedPath) {
-      ctx.matchedPath = matchedPath;
+      ctx.matchedPath = matchedPath.path;
       if (method in matchedPath[kPathMethods]) {
         return matchedPath[kPathMethods][method];
       }
index f9a2401eba045bb3b0972acac39287a07a907a01..c89cc196472a1cb6d1959126a572afb3f7789aa6 100644 (file)
@@ -298,6 +298,7 @@ describe('Router', function () {
 
       const { handler } = router.lookup(method, path, ctx);
       assert.strictEqual(handler, stubHandler);
+      assert.strictEqual(ctx.matchedPath, urlPath);
     });
     it('does not find handler with trailing slash', function () {
       router.ignoreTrailingSlash = false;