@@ -143,3 +143,60 @@ test('req.url stripping with all normalization options combined', async (t) => {
143143 await app . inject ( { method : 'GET' , url : '//secret//data//' } )
144144 t . assert . strictEqual ( capturedUrl , '/data' , '//secret//data// should strip to /data' )
145145} )
146+
147+ test ( 'req.url stripping preserves query string' , async ( t ) => {
148+ const app = Fastify ( )
149+ t . after ( ( ) => app . close ( ) )
150+
151+ await app . register ( middiePlugin )
152+
153+ let capturedUrl = null
154+
155+ app . use ( '/api' , ( req , _res , next ) => {
156+ capturedUrl = req . url
157+ next ( )
158+ } )
159+
160+ app . get ( '/api/resource' , async ( ) => ( { ok : true } ) )
161+
162+ capturedUrl = null
163+ await app . inject ( { method : 'GET' , url : '/api/resource?foo=bar' } )
164+ t . assert . strictEqual ( capturedUrl , '/resource?foo=bar' , 'single query param preserved' )
165+
166+ capturedUrl = null
167+ await app . inject ( { method : 'GET' , url : '/api/resource?foo=bar&baz=qux' } )
168+ t . assert . strictEqual ( capturedUrl , '/resource?foo=bar&baz=qux' , 'multiple query params preserved' )
169+
170+ capturedUrl = null
171+ await app . inject ( { method : 'GET' , url : '/api/resource?a=1&b=2&c=3' } )
172+ t . assert . strictEqual ( capturedUrl , '/resource?a=1&b=2&c=3' , 'many query params preserved' )
173+ } )
174+
175+ test ( 'req.url stripping preserves query string with normalization options' , async ( t ) => {
176+ const app = Fastify ( {
177+ routerOptions : {
178+ ignoreDuplicateSlashes : true ,
179+ ignoreTrailingSlash : true
180+ }
181+ } )
182+ t . after ( ( ) => app . close ( ) )
183+
184+ await app . register ( middiePlugin )
185+
186+ let capturedUrl = null
187+
188+ app . use ( '/secret' , ( req , _res , next ) => {
189+ capturedUrl = req . url
190+ next ( )
191+ } )
192+
193+ app . get ( '/secret/data' , async ( ) => ( { ok : true } ) )
194+
195+ capturedUrl = null
196+ await app . inject ( { method : 'GET' , url : '//secret/data?key=value' } )
197+ t . assert . strictEqual ( capturedUrl , '/data?key=value' , '//secret/data?key=value preserves query string' )
198+
199+ capturedUrl = null
200+ await app . inject ( { method : 'GET' , url : '/secret//data/?key=value' } )
201+ t . assert . strictEqual ( capturedUrl , '/data?key=value' , '/secret//data/?key=value preserves query string' )
202+ } )
0 commit comments