@@ -49,7 +49,7 @@ describe('methodOverrideHandlerPlugin', () => {
4949 it ( 'ignores non-POST requests' , async ( ) => {
5050 const { result, next, nextResult } = await invokeInterceptor ( {
5151 method : 'GET' ,
52- url : '/todos/1?method =DELETE' ,
52+ url : '/todos/1?_method =DELETE' ,
5353 } )
5454
5555 expect ( next ) . toHaveBeenCalledExactlyOnceWith ( )
@@ -69,7 +69,7 @@ describe('methodOverrideHandlerPlugin', () => {
6969 it ( 'overrides the method and strips the param' , async ( ) => {
7070 const { result, next, nextResult } = await invokeInterceptor ( {
7171 method : 'POST' ,
72- url : '/todos/1?method =DELETE' ,
72+ url : '/todos/1?_method =DELETE' ,
7373 } )
7474
7575 expect ( next ) . toHaveBeenCalledExactlyOnceWith (
@@ -81,7 +81,7 @@ describe('methodOverrideHandlerPlugin', () => {
8181 } )
8282
8383 it ( 'matches the override value case-insensitively' , async ( ) => {
84- const { next } = await invokeInterceptor ( { method : 'POST' , url : '/todos/1?method =delete' } )
84+ const { next } = await invokeInterceptor ( { method : 'POST' , url : '/todos/1?_method =delete' } )
8585
8686 expect ( next ) . toHaveBeenCalledExactlyOnceWith (
8787 expect . objectContaining ( {
@@ -93,7 +93,7 @@ describe('methodOverrideHandlerPlugin', () => {
9393 it ( 'uses the last occurrence when the param is repeated and strips all of them' , async ( ) => {
9494 const { next } = await invokeInterceptor ( {
9595 method : 'POST' ,
96- url : '/todos/1?method =PUT&method =DELETE' ,
96+ url : '/todos/1?_method =PUT&_method =DELETE' ,
9797 } )
9898
9999 expect ( next ) . toHaveBeenCalledExactlyOnceWith (
@@ -104,7 +104,7 @@ describe('methodOverrideHandlerPlugin', () => {
104104 } )
105105
106106 it ( 'preserves other query params and the hash' , async ( ) => {
107- const { next } = await invokeInterceptor ( { method : 'POST' , url : '/a?x=1&method =DELETE&y=2#h' } )
107+ const { next } = await invokeInterceptor ( { method : 'POST' , url : '/a?x=1&_method =DELETE&y=2#h' } )
108108
109109 expect ( next ) . toHaveBeenCalledExactlyOnceWith (
110110 expect . objectContaining ( {
@@ -118,7 +118,7 @@ describe('methodOverrideHandlerPlugin', () => {
118118 async ( method ) => {
119119 const { result, next, nextResult } = await invokeInterceptor ( {
120120 method : 'POST' ,
121- url : `/todos/1?method =${ method } ` ,
121+ url : `/todos/1?_method =${ method } ` ,
122122 } )
123123
124124 expect ( next ) . toHaveBeenCalledExactlyOnceWith ( )
@@ -128,20 +128,56 @@ describe('methodOverrideHandlerPlugin', () => {
128128
129129 it ( 'honors a custom param name' , async ( ) => {
130130 const { next } = await invokeInterceptor (
131- { method : 'POST' , url : '/todos/1?_method =DELETE&method =PUT' } ,
132- { param : '_method ' } ,
131+ { method : 'POST' , url : '/todos/1?method =DELETE&_method =PUT' } ,
132+ { param : 'method ' } ,
133133 )
134134
135135 expect ( next ) . toHaveBeenCalledExactlyOnceWith (
136136 expect . objectContaining ( {
137- request : expect . objectContaining ( { method : 'DELETE' , url : '/todos/1?method=PUT' } ) ,
137+ request : expect . objectContaining ( { method : 'DELETE' , url : '/todos/1?_method=PUT' } ) ,
138+ } ) ,
139+ )
140+ } )
141+
142+ it ( 'does not re-encode the remaining query string' , async ( ) => {
143+ const { next } = await invokeInterceptor ( {
144+ method : 'POST' ,
145+ url : '/a?q=a%20b+c&_method=DELETE&redirect=/x?y=1,2&e=%7E*&flag&&k=&?_method=keep#h' ,
146+ } )
147+
148+ expect ( next ) . toHaveBeenCalledExactlyOnceWith (
149+ expect . objectContaining ( {
150+ request : expect . objectContaining ( {
151+ method : 'DELETE' ,
152+ url : '/a?q=a%20b+c&redirect=/x?y=1,2&e=%7E*&flag&&k=&?_method=keep#h' ,
153+ } ) ,
154+ } ) ,
155+ )
156+ } )
157+
158+ it ( 'keeps a remaining empty query component' , async ( ) => {
159+ const { next } = await invokeInterceptor ( { method : 'POST' , url : '/a?_method=DELETE&' } )
160+
161+ expect ( next ) . toHaveBeenCalledExactlyOnceWith (
162+ expect . objectContaining ( {
163+ request : expect . objectContaining ( { method : 'DELETE' , url : '/a?' } ) ,
164+ } ) ,
165+ )
166+ } )
167+
168+ it ( 'matches an encoded param name' , async ( ) => {
169+ const { next } = await invokeInterceptor ( { method : 'POST' , url : '/a?%5Fmethod=DELETE&x=1' } )
170+
171+ expect ( next ) . toHaveBeenCalledExactlyOnceWith (
172+ expect . objectContaining ( {
173+ request : expect . objectContaining ( { method : 'DELETE' , url : '/a?x=1' } ) ,
138174 } ) ,
139175 )
140176 } )
141177
142178 it ( 'honors custom allowed methods' , async ( ) => {
143179 const { next } = await invokeInterceptor (
144- { method : 'POST' , url : '/todos/1?method =GET' } ,
180+ { method : 'POST' , url : '/todos/1?_method =GET' } ,
145181 { methods : [ 'get' ] } ,
146182 )
147183
@@ -152,7 +188,7 @@ describe('methodOverrideHandlerPlugin', () => {
152188 )
153189
154190 const { next : next2 } = await invokeInterceptor (
155- { method : 'POST' , url : '/todos/1?method =DELETE' } ,
191+ { method : 'POST' , url : '/todos/1?_method =DELETE' } ,
156192 { methods : [ 'GET' ] } ,
157193 )
158194
@@ -171,7 +207,7 @@ describe('methodOverrideHandlerPlugin', () => {
171207 )
172208
173209 const { matched, response } = await handler . handle (
174- new Request ( 'https://example.com/ping?method =DELETE' , {
210+ new Request ( 'https://example.com/ping?_method =DELETE' , {
175211 method : 'POST' ,
176212 headers : {
177213 'content-type' : 'application/json' ,
0 commit comments