Browse Source

refactor: removes slash duplicates from trie path

e22m4u 1 month ago
parent
commit
8e261b77fd
2 changed files with 6 additions and 2 deletions
  1. 2 1
      dist/cjs/index.cjs
  2. 4 1
      src/route-registry.js

+ 2 - 1
dist/cjs/index.cjs

@@ -1393,7 +1393,8 @@ var _RouteRegistry = class _RouteRegistry extends DebuggableService {
       req.method.toUpperCase(),
       requestPath
     );
-    const triePath = `${req.method.toUpperCase()}/${requestPath}`;
+    const rawTriePath = `${req.method.toUpperCase()}/${requestPath}`;
+    const triePath = rawTriePath.replace(/\/+/, "/");
     const resolved = this._trie.match(triePath);
     if (resolved) {
       const route = resolved.value;

+ 4 - 1
src/route-registry.js

@@ -63,7 +63,10 @@ export class RouteRegistry extends DebuggableService {
       req.method.toUpperCase(),
       requestPath,
     );
-    const triePath = `${req.method.toUpperCase()}/${requestPath}`;
+    const rawTriePath = `${req.method.toUpperCase()}/${requestPath}`;
+    // маршрут формируется с удалением дубликатов косой черты
+    // "OPTIONS//api/users/login" => "OPTIONS/api/users/login"
+    const triePath = rawTriePath.replace(/\/+/, '/');
     const resolved = this._trie.match(triePath);
     if (resolved) {
       const route = resolved.value;