Unverified Commit f8269fd4 authored by Alexander's avatar Alexander Committed by GitHub

Fix: (rewrites) incorrect parsing of destination query (#26619)

fixes #26609

## Bug

- [x]  Related issues linked using fixes #number
- [x]   Integration tests added

## Documentation / Examples

- [x]  Make sure the linting passes
parent 5b1c3e39
...@@ -209,13 +209,13 @@ export default function prepareDestination( ...@@ -209,13 +209,13 @@ export default function prepareDestination(
// update any params in query values // update any params in query values
for (const [key, strOrArray] of Object.entries(destQuery)) { for (const [key, strOrArray] of Object.entries(destQuery)) {
let value = Array.isArray(strOrArray) ? strOrArray[0] : strOrArray // the value needs to start with a forward-slash to be compiled
if (value) { // correctly
// the value needs to start with a forward-slash to be compiled if (Array.isArray(strOrArray)) {
// correctly destQuery[key] = strOrArray.map((value) => compileNonPath(value, params))
value = compileNonPath(value, params) } else {
destQuery[key] = compileNonPath(strOrArray, params)
} }
destQuery[key] = value
} }
// add path params to query if it's not a redirect and not // add path params to query if it's not a redirect and not
......
module.exports = {
rewrites() {
return [
{
source: '/some-page',
destination: '/?items=1&items=2',
},
]
},
}
export function getServerSideProps(context) {
return {
props: {
query: context.query,
},
}
}
export default function Page(props) {
return (
<>
<p id="items">{props.query.items.join(',')}</p>
</>
)
}
/* eslint-env jest */
import { join } from 'path'
import {
findPort,
killApp,
launchApp,
nextBuild,
nextStart,
} from 'next-test-utils'
import webdriver from 'next-webdriver'
jest.setTimeout(1000 * 60 * 2)
const appDir = join(__dirname, '../')
let appPort
let app
const runTests = () => {
it('should contain all values passed in param as array', async () => {
const browser = await webdriver(appPort, '/some-page')
expect(await browser.elementByCss('#items').text()).toBe('1,2')
})
}
describe('rewrites destination query', () => {
describe('dev mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
})
describe('production mode', () => {
beforeAll(async () => {
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
})
})
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