Skip to content

Commit 9437df9

Browse files
jdspughdougwilson
authored andcommitted
perf: prevent internal throw when missing charset
closes #250
1 parent fb5b8ec commit 9437df9

File tree

4 files changed

+4
-3
lines changed

4 files changed

+4
-3
lines changed

HISTORY.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ unreleased
1515
- Use `http-errors` for standard emitted errors
1616
1717
18+
* perf: prevent internal `throw` when missing charset
1819

1920
1.17.2 / 2017-05-17
2021
===================

lib/types/json.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ function firstchar (str) {
154154

155155
function getCharset (req) {
156156
try {
157-
return contentType.parse(req).parameters.charset.toLowerCase()
157+
return (contentType.parse(req).parameters.charset || '').toLowerCase()
158158
} catch (e) {
159159
return undefined
160160
}

lib/types/text.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function text (options) {
101101

102102
function getCharset (req) {
103103
try {
104-
return contentType.parse(req).parameters.charset.toLowerCase()
104+
return (contentType.parse(req).parameters.charset || '').toLowerCase()
105105
} catch (e) {
106106
return undefined
107107
}

lib/types/urlencoded.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ function extendedparser (options) {
171171

172172
function getCharset (req) {
173173
try {
174-
return contentType.parse(req).parameters.charset.toLowerCase()
174+
return (contentType.parse(req).parameters.charset || '').toLowerCase()
175175
} catch (e) {
176176
return undefined
177177
}

0 commit comments

Comments
 (0)