Skip to content

Commit d627f8e

Browse files
committed
pattern termination with impossible to match pattern
1 parent 4a87b61 commit d627f8e

3 files changed

Lines changed: 4 additions & 4 deletions

File tree

src/match.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export const router_compile_to_matcher = <T>(router: Router<T>): Matcher<T> => {
141141
regexps,
142142
handlers,
143143
matchAllStaticMap,
144-
matchAllRegExp: new RegExp('^' + node_compile_to_regexp(matchAllTree![2], true) + '$'),
144+
matchAllRegExp: new RegExp('^' + node_compile_to_regexp(matchAllTree![2], true)),
145145
matchAllHandler: HANDLERS,
146146
};
147147
};

src/tree/regex.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,9 @@ export const node_compile_to_regexp = <T>(node: Node<T>, earlyTerminate: boolean
201201
parts += '.*' + connect_node_compile_to_regexp(node[6], earlyTerminate);
202202
}
203203

204-
// early terminate
205204
parts = earlyTerminate
206-
? '(?:' + parts + '$)'
205+
? // early terminate the pattern by having an impossible pattern
206+
'(?:' + parts + '$.)'
207207
: partsCnt > 1
208208
? '(?:' + parts.slice(0, -1) + ')'
209209
: parts.slice(0, -1);

tests/node/tree/jit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const run = (name: string, suite: Suite) => {
2121
: tree_set_static(tree, pattern, `return {id:${JSON.stringify(pattern)},params:{}}`);
2222
}
2323

24-
console.log(JSON.stringify(tree, null, 2));
24+
//console.log(JSON.stringify(tree, null, 2));
2525

2626
const fn: (path: string) => { id: string; params: Record<string, string> } | undefined =
2727
Function('p', tree_compile_to_code(tree, 'r', 'p')) as any;

0 commit comments

Comments
 (0)