Unverified Commit c53b60a8 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix forward slash encoding while interpolating (#26963)

parent f8269fd4
......@@ -249,14 +249,17 @@ export function getUtils({
let paramValue: string
if (Array.isArray(params[param])) {
paramValue = (params[param] as string[]).join('/')
paramValue = (params[param] as string[])
.map((v) => v && encodeURIComponent(v))
.join('/')
} else {
paramValue = params[param] as string
paramValue =
params[param] && encodeURIComponent(params[param] as string)
}
pathname =
pathname.substr(0, paramIdx) +
encodeURI(paramValue || '') +
(paramValue || '') +
pathname.substr(paramIdx + builtParam.length)
}
}
......
......@@ -516,6 +516,28 @@ describe('Required Server Files', () => {
expect(props.params).toEqual({})
})
it('should normalize optional values correctly for SSG page with encoded slash', async () => {
const res = await fetchViaHTTP(
appPort,
'/optional-ssg/[[...rest]]',
undefined,
{
headers: {
'x-matched-path': '/optional-ssg/[[...rest]]',
'x-now-route-matches':
'1=en%2Fes%2Fhello%252Fworld&rest=en%2Fes%2Fhello%252Fworld',
},
}
)
const html = await res.text()
const $ = cheerio.load(html)
const props = JSON.parse($('#props').text())
expect(props.params).toEqual({
rest: ['en', 'es', 'hello/world'],
})
})
it('should normalize optional values correctly for API page', async () => {
const res = await fetchViaHTTP(
appPort,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment