@@ -72,4 +72,46 @@ test.describe("Next Config Redirect", () => {
72
72
} ) ;
73
73
await expect ( el ) . toBeVisible ( ) ;
74
74
} ) ;
75
+ test ( "Should properly encode the Location header for redirects with query params" , async ( {
76
+ page,
77
+ baseURL,
78
+ } ) => {
79
+ await page . goto ( "/config-redirect" ) ;
80
+ const responsePromise = page . waitForResponse ( ( response ) => {
81
+ return response . status ( ) === 307 ;
82
+ } ) ;
83
+ page . getByTestId ( "redirect-link" ) . click ( ) ;
84
+ const res = await responsePromise ;
85
+ await page . waitForURL ( "/config-redirect/dest?q=äöå€" ) ;
86
+
87
+ const locationHeader = res . headers ( ) . location ;
88
+ expect ( locationHeader ) . toBe (
89
+ `${ baseURL } /config-redirect/dest?q=%C3%A4%C3%B6%C3%A5%E2%82%AC` ,
90
+ ) ;
91
+ expect ( res . status ( ) ) . toBe ( 307 ) ;
92
+
93
+ const searchParams = page . getByTestId ( "searchParams" ) ;
94
+ await expect ( searchParams ) . toHaveText ( "q: äöå€" ) ;
95
+ } ) ;
96
+ test ( "Should respect already encoded query params" , async ( {
97
+ page,
98
+ baseURL,
99
+ } ) => {
100
+ await page . goto ( "/config-redirect" ) ;
101
+ const responsePromise = page . waitForResponse ( ( response ) => {
102
+ return response . status ( ) === 307 ;
103
+ } ) ;
104
+ page . getByTestId ( "redirect-link-already-encoded" ) . click ( ) ;
105
+ const res = await responsePromise ;
106
+ await page . waitForURL ( "/config-redirect/dest?q=äöå€" ) ;
107
+
108
+ const locationHeader = res . headers ( ) . location ;
109
+ expect ( locationHeader ) . toBe (
110
+ `${ baseURL } /config-redirect/dest?q=%C3%A4%C3%B6%C3%A5%E2%82%AC` ,
111
+ ) ;
112
+ expect ( res . status ( ) ) . toBe ( 307 ) ;
113
+
114
+ const searchParams = page . getByTestId ( "searchParams" ) ;
115
+ await expect ( searchParams ) . toHaveText ( "q: äöå€" ) ;
116
+ } ) ;
75
117
} ) ;
0 commit comments