Skip to content

Commit

Permalink
Provide static require analysis in urlencoded parser
Browse files Browse the repository at this point in the history
closes #120
closes #121
  • Loading branch information
dougwilson committed Sep 4, 2015
1 parent 79d0972 commit 9d8c719
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
unreleased
==========

* Provide static `require` analysis in `urlencoded` parser

1.13.3 / 2015-07-31
===================

Expand Down
16 changes: 13 additions & 3 deletions lib/types/urlencoded.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,22 @@ function parameterCount(body, limit) {
function parser(name) {
var mod = parsers[name]

if (mod) {
if (mod !== undefined) {
return mod.parse
}

// load module
mod = parsers[name] = require(name)
// this uses a switch for static require analysis
switch (name) {
case 'qs':
mod = require('qs')
break
case 'querystring':
mod = require('querystring')
break
}

// store to prevent invoking require()
parsers[name] = mod

return mod.parse
}
Expand Down

0 comments on commit 9d8c719

Please sign in to comment.