File tree Expand file tree Collapse file tree
src/middleware/method-override Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -95,6 +95,23 @@ describe('Method Override Middleware', () => {
9595 expect ( data . contentType ) . toBe ( 'application/x-www-form-urlencoded' )
9696 } )
9797
98+ it ( 'Should override POST to DELETE - with charset in Content-Type' , async ( ) => {
99+ const params = new URLSearchParams ( )
100+ params . append ( 'message' , 'Hello' )
101+ params . append ( '_method' , 'DELETE' )
102+ const res = await app . request ( '/posts' , {
103+ body : params ,
104+ headers : {
105+ 'Content-Type' : 'application/x-www-form-urlencoded;charset=UTF-8' ,
106+ } ,
107+ method : 'POST' ,
108+ } )
109+ expect ( res . status ) . toBe ( 200 )
110+ const data = await res . json ( )
111+ expect ( data . method ) . toBe ( 'DELETE' )
112+ expect ( data . message ) . toBe ( 'Hello' )
113+ } )
114+
98115 it ( 'Should override POST to PATCH - not found' , async ( ) => {
99116 const form = new FormData ( )
100117 form . append ( 'message' , 'Hello' )
Original file line number Diff line number Diff line change @@ -89,7 +89,7 @@ export const methodOverride = (options: MethodOverrideOptions): MiddlewareHandle
8989 }
9090 }
9191 // Content-Type is `application/x-www-form-urlencoded`
92- if ( contentType === 'application/x-www-form-urlencoded' ) {
92+ if ( contentType ?. startsWith ( 'application/x-www-form-urlencoded' ) ) {
9393 const params = await parseBody < Record < string , string > > ( clonedRequest )
9494 const method = params [ methodFormName ]
9595 if ( method ) {
You can’t perform that action at this time.
0 commit comments