@@ -25,6 +25,8 @@ var internals = {
2525 allowDots : false
2626} ;
2727
28+ var has = Object . prototype . hasOwnProperty ;
29+
2830internals . parseValues = function ( str , options ) {
2931 var obj = { } ;
3032 var parts = str . split ( options . delimiter , options . parameterLimit === Infinity ? undefined : options . parameterLimit ) ;
@@ -43,7 +45,7 @@ internals.parseValues = function (str, options) {
4345 var key = Utils . decode ( part . slice ( 0 , pos ) ) ;
4446 var val = Utils . decode ( part . slice ( pos + 1 ) ) ;
4547
46- if ( Object . prototype . hasOwnProperty . call ( obj , key ) ) {
48+ if ( has . call ( obj , key ) ) {
4749 obj [ key ] = [ ] . concat ( obj [ key ] ) . concat ( val ) ;
4850 } else {
4951 obj [ key ] = val ;
@@ -96,34 +98,35 @@ internals.parseKeys = function (givenKey, val, options) {
9698
9799 // The regex chunks
98100
99- var parent = / ^ ( [ ^ [ ] * ) / ;
101+ var brackets = / ( \[ [ ^ [ \] ] * ] ) / ;
100102 var child = / ( \[ [ ^ [ \] ] * ] ) / g;
101103
102104 // Get the parent
103105
104- var segment = parent . exec ( key ) ;
106+ var segment = brackets . exec ( key ) ;
107+ var parent = segment ? key . slice ( 0 , segment . index ) : key ;
105108
106109 // Stash the parent if it exists
107110
108111 var keys = [ ] ;
109- if ( segment [ 1 ] ) {
112+ if ( parent ) {
110113 // If we aren't using plain objects, optionally prefix keys
111114 // that would overwrite object prototype properties
112- if ( ! options . plainObjects && Object . prototype . hasOwnProperty ( segment [ 1 ] ) ) {
115+ if ( ! options . plainObjects && has . call ( Object . prototype , parent ) ) {
113116 if ( ! options . allowPrototypes ) {
114117 return ;
115118 }
116119 }
117120
118- keys . push ( segment [ 1 ] ) ;
121+ keys . push ( parent ) ;
119122 }
120123
121124 // Loop through children appending to the array until we hit depth
122125
123126 var i = 0 ;
124127 while ( ( segment = child . exec ( key ) ) !== null && i < options . depth ) {
125128 i += 1 ;
126- if ( ! options . plainObjects && Object . prototype . hasOwnProperty . call ( Object . prototype , segment [ 1 ] . slice ( 1 , - 1 ) ) ) {
129+ if ( ! options . plainObjects && has . call ( Object . prototype , segment [ 1 ] . slice ( 1 , - 1 ) ) ) {
127130 if ( ! options . allowPrototypes ) {
128131 return ;
129132 }
@@ -319,6 +322,8 @@ var hexTable = (function () {
319322 return array ;
320323} ( ) ) ;
321324
325+ var has = Object . prototype . hasOwnProperty ;
326+
322327exports . arrayToObject = function ( source , options ) {
323328 var obj = options . plainObjects ? Object . create ( null ) : { } ;
324329 for ( var i = 0 ; i < source . length ; ++ i ) {
@@ -339,7 +344,9 @@ exports.merge = function (target, source, options) {
339344 if ( Array . isArray ( target ) ) {
340345 target . push ( source ) ;
341346 } else if ( typeof target === 'object' ) {
342- target [ source ] = true ;
347+ if ( options . plainObjects || options . allowPrototypes || ! has . call ( Object . prototype , source ) ) {
348+ target [ source ] = true ;
349+ }
343350 } else {
344351 return [ target , source ] ;
345352 }
@@ -359,7 +366,7 @@ exports.merge = function (target, source, options) {
359366 return Object . keys ( source ) . reduce ( function ( acc , key ) {
360367 var value = source [ key ] ;
361368
362- if ( Object . prototype . hasOwnProperty . call ( acc , key ) ) {
369+ if ( has . call ( acc , key ) ) {
363370 acc [ key ] = exports . merge ( acc [ key ] , value , options ) ;
364371 } else {
365372 acc [ key ] = value ;
0 commit comments