Skip to content

Commit 6b7a452

Browse files
Throw on unmatched closing paren (#286)
Co-authored-by: Blake Embrey <[email protected]>
1 parent 208cc83 commit 6b7a452

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/index.spec.ts

+12
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ describe("path-to-regexp", () => {
3131
);
3232
});
3333

34+
it("should throw on unmatched )", function () {
35+
expect(() => match("/:fooab)c")).toThrow(
36+
new TypeError("Unmatched ) at 7: https://git.new/pathToRegexpError"),
37+
);
38+
});
39+
40+
it("should throw on unmatched ) after other patterns", function () {
41+
expect(() => match("/:test(\\w+)/:foo(\\d+))")).toThrow(
42+
new TypeError("Unmatched ) at 21: https://git.new/pathToRegexpError"),
43+
);
44+
});
45+
3446
it("should throw on missing pattern", () => {
3547
expect(() => match("/:foo()")).toThrow(
3648
new TypeError(

src/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ function lexer(str: string) {
199199
continue;
200200
}
201201

202+
if (value === ")") {
203+
throw new TypeError(`Unmatched ) at ${i}: ${DEBUG_URL}`);
204+
}
205+
202206
tokens.push({ type: "CHAR", index: i, value: chars[i++] });
203207
}
204208

0 commit comments

Comments
 (0)