Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit 01cf9da

Browse files
authored
Merge pull request #142 from apiaryio/honzajavorek/update-deps
Update dependencies
2 parents 0a39d93 + 54d7adc commit 01cf9da

File tree

3 files changed

+2925
-914
lines changed

3 files changed

+2925
-914
lines changed

lib/mixins/validatable-http-message.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const jph = require('json-parse-helpfulerror');
22
const mediaTyper = require('media-typer');
3+
const contentType = require('content-type');
34
const isset = require('../utils/isset');
45
const validators = require('../validators');
56

@@ -424,17 +425,23 @@ but body is not a parseable JSON:\n${error.message}\
424425
);
425426
}
426427

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
429443
return false;
430444
}
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;
438445
}
439446
}
440447

0 commit comments

Comments
 (0)