File tree Expand file tree Collapse file tree 2 files changed +37
-2
lines changed
src/server/plugins/engine Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -229,7 +229,7 @@ describe('Helpers', () => {
229229 }
230230 )
231231
232- it ( 'should not forward custom query params to the next page URL ' , ( ) => {
232+ it ( 'should not forward custom query params on POST ' , ( ) => {
233233 request = {
234234 ...request ,
235235 method : 'post' ,
@@ -240,6 +240,34 @@ describe('Helpers', () => {
240240
241241 expect ( h . redirect ) . toHaveBeenCalledWith ( '/test/next-page' )
242242 } )
243+
244+ it ( 'should forward custom query params on GET so pre-population params survive dispatch redirects' , ( ) => {
245+ request = {
246+ ...request ,
247+ method : 'get' ,
248+ query : { formId : '69afefa99b7b18cc1cd2c606' }
249+ }
250+
251+ proceed ( request , h , '/test/next-page' )
252+
253+ expect ( h . redirect ) . toHaveBeenCalledWith (
254+ '/test/next-page?formId=69afefa99b7b18cc1cd2c606'
255+ )
256+ } )
257+
258+ it ( 'should forward custom query params on GET but not returnUrl' , ( ) => {
259+ request = {
260+ ...request ,
261+ method : 'get' ,
262+ query : { formId : '69afefa99b7b18cc1cd2c606' , returnUrl : '/summary' }
263+ }
264+
265+ proceed ( request , h , '/test/next-page' )
266+
267+ expect ( h . redirect ) . toHaveBeenCalledWith (
268+ '/test/next-page?formId=69afefa99b7b18cc1cd2c606'
269+ )
270+ } )
243271 } )
244272
245273 describe ( 'encodeUrl' , ( ) => {
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import {
2222} from '~/src/server/plugins/engine/components/helpers/components.js'
2323import { type FormModel } from '~/src/server/plugins/engine/models/FormModel.js'
2424import { type PageControllerClass } from '~/src/server/plugins/engine/pageControllers/helpers/pages.js'
25+ import { stripParam } from '~/src/server/plugins/engine/pageControllers/helpers/state.js'
2526import {
2627 type AnyFormRequest ,
2728 type FormContext ,
@@ -129,11 +130,17 @@ export function proceed(
129130 payload . action === FormAction . Validate
130131 : false
131132
133+ // On POST, strip all query params to prevent them persisting across pages.
134+ // On GET, forward params (minus returnUrl) so pre-population query params
135+ // survive dispatch redirects (e.g. ?formId= reaching the start page).
136+ const nextQuery =
137+ method === 'get' ? stripParam ( query , 'returnUrl' ) : undefined
138+
132139 // Redirect to return location (optional)
133140 const response =
134141 isReturnAllowed && isPathRelative ( returnUrl )
135142 ? h . redirect ( returnUrl )
136- : h . redirect ( redirectPath ( nextUrl ) )
143+ : h . redirect ( redirectPath ( nextUrl , nextQuery ) )
137144
138145 // Redirect POST to GET to avoid resubmission
139146 return method === 'post'
You can’t perform that action at this time.
0 commit comments