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

Commit c073d61

Browse files
author
Jochen Niebuhr
committed
fix: parseKeyValue function does not allow additional equals signs
In some cases people will not follow all URL standards and may have unescaped = characters in their GET parameter values. Currently $location will not parse them correctly (or rather too correctly) and in combination with the routing will make a pushState that removes them from the URL. My proposed fix will just join everything after the key back together with the '=' character it is split by before.
1 parent b041b66 commit c073d61

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/Angular.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1129,9 +1129,9 @@ function parseKeyValue(/**string*/keyValue) {
11291129
forEach((keyValue || "").split('&'), function(keyValue) {
11301130
if ( keyValue ) {
11311131
key_value = keyValue.replace(/\+/g,'%20').split('=');
1132-
key = tryDecodeURIComponent(key_value[0]);
1132+
key = tryDecodeURIComponent(key_value.shift());
11331133
if ( isDefined(key) ) {
1134-
var val = isDefined(key_value[1]) ? tryDecodeURIComponent(key_value[1]) : true;
1134+
var val = key_value.length > 0 ? tryDecodeURIComponent(key_value.join('=')) : true;
11351135
if (!hasOwnProperty.call(obj, key)) {
11361136
obj[key] = val;
11371137
} else if(isArray(obj[key])) {

test/AngularSpec.js

+6
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,12 @@ describe('angular', function() {
505505
'toString': '123'
506506
});
507507
});
508+
509+
it('should ignore badly escaped = characters', function() {
510+
expect(parseKeyValue('test=a=b')).toEqual({
511+
'test': 'a=b'
512+
});
513+
});
508514
});
509515

510516
describe('toKeyValue', function() {

0 commit comments

Comments
 (0)