Skip to content

Commit

Permalink
Fix Double URL Encoding for Serverless (#10663)
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer committed Feb 24, 2020
1 parent c3f11c2 commit c3d9149
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
Expand Up @@ -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]
}),
{}
);
Expand Down
5 changes: 5 additions & 0 deletions test/integration/serverless/pages/catchall/[...slug].js
@@ -0,0 +1,5 @@
const SlugPage = ({ query }) => <div>{JSON.stringify(query)}</div>

SlugPage.getInitialProps = ({ query }) => ({ query })

export default SlugPage
24 changes: 22 additions & 2 deletions test/integration/serverless/test/index.test.js
Expand Up @@ -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())
Expand Down

0 comments on commit c3d9149

Please sign in to comment.