diff --git a/packages/next/build/webpack/loaders/next-serverless-loader.ts b/packages/next/build/webpack/loaders/next-serverless-loader.ts index 38440685b423213..6d92d5092494514 100644 --- a/packages/next/build/webpack/loaders/next-serverless-loader.ts +++ b/packages/next/build/webpack/loaders/next-serverless-loader.ts @@ -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] }), {} ); diff --git a/test/integration/serverless/pages/catchall/[...slug].js b/test/integration/serverless/pages/catchall/[...slug].js new file mode 100644 index 000000000000000..0f2990960563602 --- /dev/null +++ b/test/integration/serverless/pages/catchall/[...slug].js @@ -0,0 +1,5 @@ +const SlugPage = ({ query }) =>
{JSON.stringify(query)}
+ +SlugPage.getInitialProps = ({ query }) => ({ query }) + +export default SlugPage diff --git a/test/integration/serverless/test/index.test.js b/test/integration/serverless/test/index.test.js index ce9d5fc79afd785..79ca395a371ea6a 100644 --- a/test/integration/serverless/test/index.test.js +++ b/test/integration/serverless/test/index.test.js @@ -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())