@@ -13,6 +13,8 @@ var internals = {
1313 allowDots : false
1414} ;
1515
16+ var has = Object . prototype . hasOwnProperty ;
17+
1618internals . parseValues = function ( str , options ) {
1719 var obj = { } ;
1820 var parts = str . split ( options . delimiter , options . parameterLimit === Infinity ? undefined : options . parameterLimit ) ;
@@ -31,7 +33,7 @@ internals.parseValues = function (str, options) {
3133 var key = Utils . decode ( part . slice ( 0 , pos ) ) ;
3234 var val = Utils . decode ( part . slice ( pos + 1 ) ) ;
3335
34- if ( Object . prototype . hasOwnProperty . call ( obj , key ) ) {
36+ if ( has . call ( obj , key ) ) {
3537 obj [ key ] = [ ] . concat ( obj [ key ] ) . concat ( val ) ;
3638 } else {
3739 obj [ key ] = val ;
@@ -84,34 +86,35 @@ internals.parseKeys = function (givenKey, val, options) {
8486
8587 // The regex chunks
8688
87- var parent = / ^ ( [ ^ [ ] * ) / ;
89+ var brackets = / ( \[ [ ^ [ \] ] * ] ) / ;
8890 var child = / ( \[ [ ^ [ \] ] * ] ) / g;
8991
9092 // Get the parent
9193
92- var segment = parent . exec ( key ) ;
94+ var segment = brackets . exec ( key ) ;
95+ var parent = segment ? key . slice ( 0 , segment . index ) : key ;
9396
9497 // Stash the parent if it exists
9598
9699 var keys = [ ] ;
97- if ( segment [ 1 ] ) {
100+ if ( parent ) {
98101 // If we aren't using plain objects, optionally prefix keys
99102 // that would overwrite object prototype properties
100- if ( ! options . plainObjects && Object . prototype . hasOwnProperty ( segment [ 1 ] ) ) {
103+ if ( ! options . plainObjects && has . call ( Object . prototype , parent ) ) {
101104 if ( ! options . allowPrototypes ) {
102105 return ;
103106 }
104107 }
105108
106- keys . push ( segment [ 1 ] ) ;
109+ keys . push ( parent ) ;
107110 }
108111
109112 // Loop through children appending to the array until we hit depth
110113
111114 var i = 0 ;
112115 while ( ( segment = child . exec ( key ) ) !== null && i < options . depth ) {
113116 i += 1 ;
114- if ( ! options . plainObjects && Object . prototype . hasOwnProperty . call ( Object . prototype , segment [ 1 ] . slice ( 1 , - 1 ) ) ) {
117+ if ( ! options . plainObjects && has . call ( Object . prototype , segment [ 1 ] . slice ( 1 , - 1 ) ) ) {
115118 if ( ! options . allowPrototypes ) {
116119 return ;
117120 }
0 commit comments