File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
packages/next/shared/lib/router/utils
test/integration/route-index/test Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import type { NextParsedUrlQuery } from '../../../../server/request-meta'
4
4
import type { Params } from '../../../../server/router'
5
5
import type { RouteHas } from '../../../../lib/load-custom-routes'
6
6
import { compile , pathToRegexp } from 'next/dist/compiled/path-to-regexp'
7
+ import escapeStringRegexp from 'next/dist/compiled/escape-string-regexp'
7
8
import { parseUrl } from './parse-url'
8
9
9
10
export function matchHas (
@@ -240,7 +241,7 @@ function getSafeParamName(paramName: string) {
240
241
241
242
function escapeSegment ( str : string , segmentName : string ) {
242
243
return str . replace (
243
- new RegExp ( `:${ segmentName } ` , 'g' ) ,
244
+ new RegExp ( `:${ escapeStringRegexp ( segmentName ) } ` , 'g' ) ,
244
245
`__ESC_COLON_${ segmentName } `
245
246
)
246
247
}
Original file line number Diff line number Diff line change @@ -32,6 +32,19 @@ const runTests = () => {
32
32
expect ( res . status ) . toBe ( 404 )
33
33
expect ( await res . text ( ) ) . toContain ( 'page could not be found' )
34
34
} )
35
+
36
+ it ( 'should handle /index/?bar%60%3C%25%22%27%7B%24%2A%25%5C correctly' , async ( ) => {
37
+ const res = await fetchViaHTTP (
38
+ appPort ,
39
+ '/index/?bar%60%3C%25%22%27%7B%24%2A%25%5C'
40
+ )
41
+ expect ( res . status ) . toBe ( 200 )
42
+ } )
43
+
44
+ it ( 'should handle /index?file%3A%5C correctly' , async ( ) => {
45
+ const res = await fetchViaHTTP ( appPort , '/index?file%3A%5C' )
46
+ expect ( res . status ) . toBe ( 200 )
47
+ } )
35
48
}
36
49
37
50
describe ( 'Route index handling' , ( ) => {
You can’t perform that action at this time.
0 commit comments