Unverified Commit c3d91491 authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

Fix Double URL Encoding for Serverless (#10663)

parent c3f11c20
...@@ -301,7 +301,7 @@ const nextServerlessLoader: loader.Loader = function() { ...@@ -301,7 +301,7 @@ const nextServerlessLoader: loader.Loader = function() {
return Object.keys(obj).reduce( return Object.keys(obj).reduce(
(prev, key) => (prev, key) =>
Object.assign(prev, { 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', () => { ...@@ -251,10 +251,30 @@ describe('Serverless', () => {
expect(data.query).toEqual({ slug: paramRaw }) 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 paramRaw = 'test % 123'
const html = await fetchViaHTTP(appPort, `/dr/[slug]`, '', { 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()) }).then(res => res.text())
const $ = cheerio.load(html) const $ = cheerio.load(html)
const data = JSON.parse($('#__NEXT_DATA__').html()) const data = JSON.parse($('#__NEXT_DATA__').html())
......
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