Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 873acf8

Browse files
committed
fix(parseKeyValue): ignore properties in prototype chain.
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 #8070 Fixes #8068
1 parent 9063a0c commit 873acf8

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Angular.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,7 @@ function parseKeyValue(/**string*/keyValue) {
11051105
key = tryDecodeURIComponent(key_value[0]);
11061106
if ( isDefined(key) ) {
11071107
var val = isDefined(key_value[1]) ? tryDecodeURIComponent(key_value[1]) : true;
1108-
if (!obj[key]) {
1108+
if (!hasOwnProperty.call(obj, key)) {
11091109
obj[key] = val;
11101110
} else if(isArray(obj[key])) {
11111111
obj[key].push(val);

test/AngularSpec.js

+7
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,13 @@ describe('angular', function() {
470470
expect(parseKeyValue('flag1&flag1=value&flag1=value2&flag1')).
471471
toEqual({flag1: [true,'value','value2',true]});
472472
});
473+
474+
475+
it('should ignore properties higher in the prototype chain', function() {
476+
expect(parseKeyValue('toString=123')).toEqual({
477+
'toString': '123'
478+
});
479+
});
473480
});
474481

475482
describe('toKeyValue', function() {

0 commit comments

Comments
 (0)