File tree Expand file tree Collapse file tree 5 files changed +23
-14
lines changed Expand file tree Collapse file tree 5 files changed +23
-14
lines changed Original file line number Diff line number Diff line change @@ -34,8 +34,21 @@ module.exports = generic
3434 * @public
3535 */
3636
37- function generic ( options ) {
38- var opts = options || { }
37+ function generic ( parserOptions , parserOverrides ) {
38+ var opts = { }
39+
40+ // Squash the options and the overrides down into one object
41+ var squashKey
42+ for ( squashKey in ( parserOptions || { } ) ) {
43+ if ( Object . prototype . hasOwnProperty . call ( parserOptions , squashKey ) ) {
44+ opts [ squashKey ] = parserOptions [ squashKey ]
45+ }
46+ }
47+ for ( squashKey in ( parserOverrides || { } ) ) {
48+ if ( Object . prototype . hasOwnProperty . call ( parserOverrides , squashKey ) ) {
49+ opts [ squashKey ] = parserOverrides [ squashKey ]
50+ }
51+ }
3952
4053 var limit = typeof opts . limit !== 'number'
4154 ? bytes . parse ( opts . limit || '100kb' )
Original file line number Diff line number Diff line change 1212 * @private
1313 */
1414
15- var assign = require ( 'object-assign' )
1615var genericParser = require ( '../..' ) . generic
1716var debug = require ( 'debug' ) ( 'body-parser:json' )
1817
@@ -55,7 +54,7 @@ function json (options) {
5554 var parser = opts . parser || JSON . parse
5655 var type = opts . type || 'application/json'
5756
58- return genericParser ( assign ( { } , opts , {
57+ return genericParser ( opts , {
5958 type : type ,
6059
6160 charset : function validateCharset ( charset ) {
@@ -88,7 +87,7 @@ function json (options) {
8887 } )
8988 }
9089 }
91- } ) )
90+ } )
9291}
9392
9493/**
Original file line number Diff line number Diff line change 1010 * Module dependencies.
1111 */
1212
13- var assign = require ( 'object-assign' )
1413var genericParser = require ( '../..' ) . generic
1514
1615/**
@@ -32,7 +31,7 @@ function raw (options) {
3231
3332 var type = opts . type || 'application/octet-stream'
3433
35- return genericParser ( assign ( { } , opts , {
34+ return genericParser ( opts , {
3635 type : type
37- } ) )
36+ } )
3837}
Original file line number Diff line number Diff line change 1010 * Module dependencies.
1111 */
1212
13- var assign = require ( 'object-assign' )
1413var genericParser = require ( '../..' ) . generic
1514
1615/**
@@ -33,9 +32,9 @@ function text (options) {
3332 var defaultCharset = opts . defaultCharset || 'utf-8'
3433 var type = opts . type || 'text/plain'
3534
36- return genericParser ( assign ( { } , opts , {
35+ return genericParser ( opts , {
3736 type : type ,
3837 charset : function validateCharset ( ) { return true } ,
3938 defaultCharset : defaultCharset
40- } ) )
39+ } )
4140}
Original file line number Diff line number Diff line change 1212 * @private
1313 */
1414
15- var assign = require ( 'object-assign' )
1615var createError = require ( 'http-errors' )
1716var debug = require ( 'debug' ) ( 'body-parser:urlencoded' )
1817var genericParser = require ( '../..' ) . generic
@@ -47,7 +46,7 @@ function urlencoded (options) {
4746 : simpleparser ( opts )
4847 )
4948
50- return genericParser ( assign ( { } , opts , {
49+ return genericParser ( opts , {
5150 type : type ,
5251 charset : charset ,
5352
@@ -56,7 +55,7 @@ function urlencoded (options) {
5655 ? queryparse ( buf )
5756 : { }
5857 }
59- } ) )
58+ } )
6059}
6160
6261/**
You can’t perform that action at this time.
0 commit comments