@@ -14,6 +14,8 @@ module.exports = {
14
14
15
15
var Utils = require ( './utils' ) ;
16
16
17
+ var has = Object . prototype . hasOwnProperty ;
18
+
17
19
var defaults = {
18
20
delimiter : '&' ,
19
21
depth : 5 ,
@@ -34,21 +36,18 @@ var parseValues = function parseValues(str, options) {
34
36
var part = parts [ i ] ;
35
37
var pos = part . indexOf ( ']=' ) === - 1 ? part . indexOf ( '=' ) : part . indexOf ( ']=' ) + 1 ;
36
38
39
+ var key , val ;
37
40
if ( pos === - 1 ) {
38
- obj [ options . decoder ( part ) ] = '' ;
39
-
40
- if ( options . strictNullHandling ) {
41
- obj [ options . decoder ( part ) ] = null ;
42
- }
41
+ key = options . decoder ( part ) ;
42
+ val = options . strictNullHandling ? null : '' ;
43
43
} else {
44
- var key = options . decoder ( part . slice ( 0 , pos ) ) ;
45
- var val = options . decoder ( part . slice ( pos + 1 ) ) ;
46
-
47
- if ( Object . prototype . hasOwnProperty . call ( obj , key ) ) {
48
- obj [ key ] = [ ] . concat ( obj [ key ] ) . concat ( val ) ;
49
- } else {
50
- obj [ key ] = val ;
51
- }
44
+ key = options . decoder ( part . slice ( 0 , pos ) ) ;
45
+ val = options . decoder ( part . slice ( pos + 1 ) ) ;
46
+ }
47
+ if ( has . call ( obj , key ) ) {
48
+ obj [ key ] = [ ] . concat ( obj [ key ] ) . concat ( val ) ;
49
+ } else {
50
+ obj [ key ] = val ;
52
51
}
53
52
}
54
53
@@ -110,7 +109,7 @@ var parseKeys = function parseKeys(givenKey, val, options) {
110
109
if ( segment [ 1 ] ) {
111
110
// If we aren't using plain objects, optionally prefix keys
112
111
// that would overwrite object prototype properties
113
- if ( ! options . plainObjects && Object . prototype . hasOwnProperty ( segment [ 1 ] ) ) {
112
+ if ( ! options . plainObjects && has . call ( Object . prototype , segment [ 1 ] ) ) {
114
113
if ( ! options . allowPrototypes ) {
115
114
return ;
116
115
}
@@ -124,7 +123,7 @@ var parseKeys = function parseKeys(givenKey, val, options) {
124
123
var i = 0 ;
125
124
while ( ( segment = child . exec ( key ) ) !== null && i < options . depth ) {
126
125
i += 1 ;
127
- if ( ! options . plainObjects && Object . prototype . hasOwnProperty ( segment [ 1 ] . replace ( / \[ | \] / g, '' ) ) ) {
126
+ if ( ! options . plainObjects && has . call ( Object . prototype , segment [ 1 ] . replace ( / \[ | \] / g, '' ) ) ) {
128
127
if ( ! options . allowPrototypes ) {
129
128
continue ;
130
129
}
0 commit comments