This repository was archived by the owner on Mar 20, 2023. It is now read-only.
File tree 2 files changed +19
-2
lines changed 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -522,6 +522,23 @@ describe('test harness', () => {
522
522
} ) ;
523
523
} ) ;
524
524
525
+ it ( 'does not accept unknown pre-parsed POST raw Buffer' , async ( ) => {
526
+ var app = express ( ) ;
527
+ app . use ( bodyParser . raw ( { type : '*/*' } ) ) ;
528
+
529
+ app . use ( urlString ( ) , graphqlHTTP ( { schema : TestSchema } ) ) ;
530
+
531
+ var req = request ( app )
532
+ . post ( urlString ( ) )
533
+ . set ( 'Content-Type' , 'application/graphql' ) ;
534
+ req . write ( new Buffer ( '{ test(who: "World") }' ) ) ;
535
+ var error = await catchError ( req ) ;
536
+
537
+ expect ( error . response . status ) . to . equal ( 400 ) ;
538
+ expect ( JSON . parse ( error . response . text ) ) . to . deep . equal ( {
539
+ errors : [ { message : 'Must provide query string.' } ]
540
+ } ) ;
541
+ } ) ;
525
542
} ) ;
526
543
527
544
describe ( 'Pretty printing' , ( ) => {
Original file line number Diff line number Diff line change @@ -18,8 +18,8 @@ import type { Request } from 'express';
18
18
19
19
export function parseBody ( req : Request , next : NodeCallback ) : void {
20
20
try {
21
- // If express has already parsed a body as an object, use it.
22
- if ( typeof req . body === 'object' ) {
21
+ // If express has already parsed a body as a keyed object, use it.
22
+ if ( typeof req . body === 'object' && ! ( req . body instanceof Buffer ) ) {
23
23
return next ( null , req . body ) ;
24
24
}
25
25
You can’t perform that action at this time.
0 commit comments