diff --git a/HISTORY.md b/HISTORY.md index d81117d5..fcd5bd72 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,8 @@ +unreleased +========== + + * Provide static `require` analysis in `urlencoded` parser + 1.13.3 / 2015-07-31 =================== diff --git a/lib/types/urlencoded.js b/lib/types/urlencoded.js index f3e76f8d..b9960fdb 100644 --- a/lib/types/urlencoded.js +++ b/lib/types/urlencoded.js @@ -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 }