Skip to content

Commit

Permalink
Throw on unmatched closing paren (#286)
Browse files Browse the repository at this point in the history
Co-authored-by: Blake Embrey <[email protected]>
  • Loading branch information
Lord-Kamina and blakeembrey committed Jul 25, 2024
1 parent 208cc83 commit 6b7a452
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ describe("path-to-regexp", () => {
);
});

it("should throw on unmatched )", function () {
expect(() => match("/:fooab)c")).toThrow(
new TypeError("Unmatched ) at 7: https://git.new/pathToRegexpError"),
);
});

it("should throw on unmatched ) after other patterns", function () {
expect(() => match("/:test(\\w+)/:foo(\\d+))")).toThrow(
new TypeError("Unmatched ) at 21: https://git.new/pathToRegexpError"),
);
});

it("should throw on missing pattern", () => {
expect(() => match("/:foo()")).toThrow(
new TypeError(
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ function lexer(str: string) {
continue;
}

if (value === ")") {
throw new TypeError(`Unmatched ) at ${i}: ${DEBUG_URL}`);
}

tokens.push({ type: "CHAR", index: i, value: chars[i++] });
}

Expand Down

0 comments on commit 6b7a452

Please sign in to comment.