File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff 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 (
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments