Skip to content

Commit

Permalink
Changing body parser slightly to do form encoding or json parsing, up…
Browse files Browse the repository at this point in the history
…dating `regex. json_wrap`
  • Loading branch information
avoidwork committed May 17, 2017
1 parent 0f5f2e0 commit 46a0ff9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
4 changes: 1 addition & 3 deletions lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ function parse (req, res, next) {
iterate(args, i => {
req.body[i[0]] = coerce(decodeURIComponent(i[1]));
});
}

if (regex.encode_json.test(type)) {
} else if (regex.encode_json.test(type) || regex.json_wrap.test(req.body)) {
try {
req.body = JSON.parse(req.body);
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion lib/regex.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const path = require("path"),
encode_json: /application\/json/,
get_rewrite: /HEAD|OPTIONS/,
has_param: /\/:(\w*)/,
json_wrap: /^[\[\{]/,
json_wrap: /^[\[\{"]/,
leading: /.*\//,
mimetype: /;.*/,
modify: /DELETE|PATCH|POST|PUT/,
Expand Down

0 comments on commit 46a0ff9

Please sign in to comment.