未验证 提交 c3d91491 编写于 作者: J Joe Haddad 提交者: GitHub

Fix Double URL Encoding for Serverless (#10663)

上级 c3f11c20
......@@ -301,7 +301,7 @@ const nextServerlessLoader: loader.Loader = function() {
return Object.keys(obj).reduce(
(prev, key) =>
Object.assign(prev, {
[key]: encodeURIComponent(obj[key])
[key]: obj[key]
}),
{}
);
......
const SlugPage = ({ query }) => <div>{JSON.stringify(query)}</div>
SlugPage.getInitialProps = ({ query }) => ({ query })
export default SlugPage
......@@ -251,10 +251,30 @@ describe('Serverless', () => {
expect(data.query).toEqual({ slug: paramRaw })
})
it('should have the correct query string for a spr route', async () => {
it('should have the correct query string for a now route', async () => {
const paramRaw = 'test % 123'
const html = await fetchViaHTTP(appPort, `/dr/[slug]`, '', {
headers: { 'x-now-route-matches': qs.stringify({ 1: paramRaw }) },
headers: {
'x-now-route-matches': qs.stringify({
1: encodeURIComponent(paramRaw),
}),
},
}).then(res => res.text())
const $ = cheerio.load(html)
const data = JSON.parse($('#__NEXT_DATA__').html())
expect(data.query).toEqual({ slug: paramRaw })
})
it('should have the correct query string for a catch all now route', async () => {
const paramRaw = ['nested % 1', 'nested/2']
const html = await fetchViaHTTP(appPort, `/catchall/[...slug]`, '', {
headers: {
'x-now-route-matches': qs.stringify({
1: paramRaw.map(e => encodeURIComponent(e)).join('/'),
}),
},
}).then(res => res.text())
const $ = cheerio.load(html)
const data = JSON.parse($('#__NEXT_DATA__').html())
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册