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

Commit cb42766

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 0958489 commit cb42766

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
@@ -1091,7 +1091,7 @@ function parseKeyValue(/**string*/keyValue) {
10911091
key = tryDecodeURIComponent(key_value[0]);
10921092
if ( isDefined(key) ) {
10931093
var val = isDefined(key_value[1]) ? tryDecodeURIComponent(key_value[1]) : true;
1094-
if (!obj[key]) {
1094+
if (!hasOwnProperty.call(obj, key)) {
10951095
obj[key] = val;
10961096
} else if(isArray(obj[key])) {
10971097
obj[key].push(val);

test/AngularSpec.js

+7
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,13 @@ describe('angular', function() {
480480
expect(parseKeyValue('flag1&flag1=value&flag1=value2&flag1')).
481481
toEqual({flag1: [true,'value','value2',true]});
482482
});
483+
484+
485+
it('should ignore properties higher in the prototype chain', function() {
486+
expect(parseKeyValue('toString=123')).toEqual({
487+
'toString': '123'
488+
});
489+
});
483490
});
484491

485492
describe('toKeyValue', function() {

0 commit comments

Comments
 (0)