@@ -11,6 +11,8 @@ const getSuiteHierarchy = (suite?: RunnerTestSuite) => {
1111 return res
1212}
1313
14+ const lineTerminators = [ '\n' , '\r' , '\u2028' , '\u2029' ]
15+
1416export const runTest = ( {
1517 skip = [ ] ,
1618 newRouter,
@@ -237,6 +239,11 @@ export const runTest = ({
237239 expect ( res . length ) . toBe ( 0 )
238240 } )
239241
242+ it . each ( lineTerminators ) ( 'Regexp dot does not match %j' , ( char ) => {
243+ router . add ( 'GET' , '/:id{.+}' , 'pattern' )
244+ expect ( match ( 'GET' , `/a${ char } b` ) ) . toEqual ( [ ] )
245+ } )
246+
240247 it ( 'Parameter with {.*} regexp' , ( ) => {
241248 router . add ( 'GET' , '/files/:name{.*}' , 'file' )
242249 let res = match ( 'GET' , '/files' )
@@ -454,6 +461,10 @@ export const runTest = ({
454461 expect ( res [ 2 ] . handler ) . toEqual ( '/x' )
455462 expect ( res [ 3 ] . handler ) . toEqual ( '/x/*' )
456463 } )
464+
465+ it . each ( lineTerminators ) ( 'Matches a line terminator %j' , ( char ) => {
466+ expect ( match ( 'GET' , `/a${ char } b` ) . map ( ( { handler } ) => handler ) ) . toEqual ( [ '/*' , '*' ] )
467+ } )
457468 } )
458469
459470 describe ( 'Suffix wildcard' , ( ) => {
@@ -516,6 +527,10 @@ export const runTest = ({
516527 const res = match ( 'GET' , '/pathfoo' )
517528 expect ( res . length ) . toBe ( 0 )
518529 } )
530+
531+ it . each ( lineTerminators ) ( 'Matches a line terminator %j' , ( char ) => {
532+ expect ( match ( 'GET' , `/path/a${ char } b` ) ) . toEqual ( [ { handler : 'path' , params : { } } ] )
533+ } )
519534 } )
520535
521536 describe ( 'Trailing wildcard after a label' , ( ) => {
@@ -956,6 +971,16 @@ export const runTest = ({
956971 expect ( res [ 1 ] . handler ) . toEqual ( 'get () name' )
957972 expect ( res [ 1 ] . params [ 'name' ] ) . toEqual ( 'hono' )
958973 } )
974+
975+ it . each ( lineTerminators ) ( 'line terminator %j' , ( char ) => {
976+ router . add ( 'ALL' , `/a${ char } b/*` , 'middleware' )
977+ router . add ( 'GET' , `/a${ char } b/:name` , 'get name' )
978+ expect ( match ( 'GET' , `/a${ char } b/hono` ) ) . toEqual ( [
979+ { handler : 'middleware' , params : { } } ,
980+ { handler : 'get name' , params : { name : 'hono' } } ,
981+ ] )
982+ expect ( match ( 'GET' , '/ab/hono' ) ) . toEqual ( [ ] )
983+ } )
959984 } )
960985
961986 describe ( 'REST API' , ( ) => {
0 commit comments