Skip to content

Commit 0809c20

Browse files
authored
fix(gatsby): fix decoding issue in SSR (#35346)
1 parent e17e533 commit 0809c20

File tree

3 files changed

+22
-1
lines changed
  • e2e-tests
    • development-runtime/cypress/integration
    • production-runtime/cypress/integration
  • packages/gatsby/src/utils/page-ssr-module

3 files changed

+22
-1
lines changed

e2e-tests/development-runtime/cypress/integration/ssr.js

+8
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ describe(`Static path ('${staticPath}')`, () => {
3535
cy.getTestElement(`query`).contains(`{}`)
3636
cy.getTestElement(`params`).contains(`{}`)
3737
})
38+
39+
it(`Preserves window.location.search as querystring passed`, () => {
40+
const queryString = `?a=b%23&x=y%25&j=`
41+
cy.visit(staticPath + queryString).waitForRouteChange()
42+
cy.window().then(win => {
43+
expect(win.location.search).to.equal(queryString)
44+
})
45+
})
3846
})
3947

4048
describe(`Param path ('${paramPath}:param')`, () => {

e2e-tests/production-runtime/cypress/integration/ssr.js

+8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ describe(`Static path ('${staticPath}')`, () => {
3636
cy.getTestElement(`query`).contains(`{}`)
3737
cy.getTestElement(`params`).contains(`{}`)
3838
})
39+
40+
it("Preserves window.location.search as querystring passed", () => {
41+
const queryString = `?a=b%23&x=y%25&j=`
42+
cy.visit(staticPath + queryString).waitForRouteChange()
43+
cy.window().then(win => {
44+
expect(win.location.search).to.equal(queryString)
45+
})
46+
})
3947
})
4048

4149
describe(`Param path ('${paramPath}:param')`, () => {

packages/gatsby/src/utils/page-ssr-module/entry.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,14 @@ export async function getData({
209209
results.pageContext = page.context
210210

211211
let searchString = ``
212+
212213
if (req?.query) {
213214
const maybeQueryString = Object.entries(req.query)
214-
.map(([k, v]) => `${k}=${v}`)
215+
.map(
216+
([k, v]) =>
217+
// Preserve QueryString encoding
218+
`${encodeURIComponent(k)}=${encodeURIComponent(v as string)}`
219+
)
215220
.join(`&`)
216221
if (maybeQueryString) {
217222
searchString = `?${maybeQueryString}`

0 commit comments

Comments
 (0)