From 9437df92ef6a03f449e55c05c9b5efccd6239ea0 Mon Sep 17 00:00:00 2001 From: Jonathan Pugh Date: Thu, 22 Jun 2017 14:23:48 -0400 Subject: [PATCH] perf: prevent internal throw when missing charset closes #250 --- HISTORY.md | 1 + lib/types/json.js | 2 +- lib/types/text.js | 2 +- lib/types/urlencoded.js | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 39160bb2..d2fe0bff 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -15,6 +15,7 @@ unreleased - Use `http-errors` for standard emitted errors - deps: bytes@2.5.0 - deps: iconv-lite@0.4.18 + * perf: prevent internal `throw` when missing charset 1.17.2 / 2017-05-17 =================== diff --git a/lib/types/json.js b/lib/types/json.js index 469123a7..7f10be08 100644 --- a/lib/types/json.js +++ b/lib/types/json.js @@ -154,7 +154,7 @@ function firstchar (str) { function getCharset (req) { try { - return contentType.parse(req).parameters.charset.toLowerCase() + return (contentType.parse(req).parameters.charset || '').toLowerCase() } catch (e) { return undefined } diff --git a/lib/types/text.js b/lib/types/text.js index 8bf26375..083a0090 100644 --- a/lib/types/text.js +++ b/lib/types/text.js @@ -101,7 +101,7 @@ function text (options) { function getCharset (req) { try { - return contentType.parse(req).parameters.charset.toLowerCase() + return (contentType.parse(req).parameters.charset || '').toLowerCase() } catch (e) { return undefined } diff --git a/lib/types/urlencoded.js b/lib/types/urlencoded.js index 08157ae1..763e556a 100644 --- a/lib/types/urlencoded.js +++ b/lib/types/urlencoded.js @@ -171,7 +171,7 @@ function extendedparser (options) { function getCharset (req) { try { - return contentType.parse(req).parameters.charset.toLowerCase() + return (contentType.parse(req).parameters.charset || '').toLowerCase() } catch (e) { return undefined }