This repository was archived by the owner on Nov 8, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +2925
-914
lines changed Expand file tree Collapse file tree 3 files changed +2925
-914
lines changed Original file line number Diff line number Diff line change 1
1
const jph = require ( 'json-parse-helpfulerror' ) ;
2
2
const mediaTyper = require ( 'media-typer' ) ;
3
+ const contentType = require ( 'content-type' ) ;
3
4
const isset = require ( '../utils/isset' ) ;
4
5
const validators = require ( '../validators' ) ;
5
6
@@ -424,17 +425,23 @@ but body is not a parseable JSON:\n${error.message}\
424
425
) ;
425
426
}
426
427
427
- isJsonContentType ( contentType ) {
428
- if ( ! contentType ) {
428
+ isJsonContentType ( contentTypeValue ) {
429
+ if ( ! contentTypeValue ) {
430
+ return false ;
431
+ }
432
+ try {
433
+ const { type } = contentType . parse ( `${ contentTypeValue } ` ) ;
434
+ const parsed = mediaTyper . parse ( type ) ;
435
+ return (
436
+ ( parsed . type === 'application' && parsed . subtype === 'json' )
437
+ || parsed . suffix === 'json'
438
+ ) ;
439
+ } catch ( e ) {
440
+ // The Content-Type value is basically a user input, it can be any
441
+ // kind of rubbish, and it is neither this function's nor Gavel's problem
442
+ // if it's invalid
429
443
return false ;
430
444
}
431
-
432
- const parsed = mediaTyper . parse ( `${ contentType } ` ) ;
433
- const isJson =
434
- ( parsed . type === 'application' && parsed . subtype === 'json' ) ||
435
- parsed . suffix === 'json' ;
436
-
437
- return isJson ;
438
445
}
439
446
}
440
447
You can’t perform that action at this time.
0 commit comments