Skip to content

Commit

Permalink
fix(parseKeyValue): ignore properties in prototype chain.
Browse files Browse the repository at this point in the history
Previously, properties (typically functions) in the prototype chain (Object.prototype) would shadow
query parameters, and cause them to be serialized incorrectly.

This CL guards against this by using hasOwnProperty() to ensure that only own properties are a concern.

Closes angular#8070
Fixes angular#8068
  • Loading branch information
caitp committed Jul 4, 2014
1 parent 03cbc0d commit b39e04f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ function parseKeyValue(/**string*/keyValue) {
key = tryDecodeURIComponent(key_value[0]);
if ( isDefined(key) ) {
var val = isDefined(key_value[1]) ? tryDecodeURIComponent(key_value[1]) : true;
if (!obj[key]) {
if (!hasOwnProperty.call(obj, key)) {
obj[key] = val;
} else if(isArray(obj[key])) {
obj[key].push(val);
Expand Down
7 changes: 7 additions & 0 deletions test/AngularSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,13 @@ describe('angular', function() {
expect(parseKeyValue('flag1&flag1=value&flag1=value2&flag1')).
toEqual({flag1: [true,'value','value2',true]});
});


it('should ignore properties higher in the prototype chain', function() {
expect(parseKeyValue('toString=123')).toEqual({
'toString': '123'
});
});
});

describe('toKeyValue', function() {
Expand Down

0 comments on commit b39e04f

Please sign in to comment.