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

Commit f13852c

Browse files
Jochen Niebuhrpetebacondarwin
Jochen Niebuhr
authored andcommitted
fix(Angular): allow unescaped = signs in values in parseKeyValue
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 dropping everything after the unescaped =. This change includes all characters after the first `=` up to the next `&`. Closes #12351
1 parent 5298672 commit f13852c

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/Angular.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -1250,13 +1250,19 @@ function tryDecodeURIComponent(value) {
12501250
* @returns {Object.<string,boolean|Array>}
12511251
*/
12521252
function parseKeyValue(/**string*/keyValue) {
1253-
var obj = {}, key_value, key;
1253+
var obj = {};
12541254
forEach((keyValue || "").split('&'), function(keyValue) {
1255+
var splitPoint, key, val;
12551256
if (keyValue) {
1256-
key_value = keyValue.replace(/\+/g,'%20').split('=');
1257-
key = tryDecodeURIComponent(key_value[0]);
1257+
key = keyValue = keyValue.replace(/\+/g,'%20');
1258+
splitPoint = keyValue.indexOf('=');
1259+
if (splitPoint !== -1) {
1260+
key = keyValue.substring(0, splitPoint);
1261+
val = keyValue.substring(splitPoint + 1);
1262+
}
1263+
key = tryDecodeURIComponent(key);
12581264
if (isDefined(key)) {
1259-
var val = isDefined(key_value[1]) ? tryDecodeURIComponent(key_value[1]) : true;
1265+
val = isDefined(val) ? tryDecodeURIComponent(val) : true;
12601266
if (!hasOwnProperty.call(obj, key)) {
12611267
obj[key] = val;
12621268
} else if (isArray(obj[key])) {

test/AngularSpec.js

+6
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,12 @@ describe('angular', function() {
994994
'toString': '123'
995995
});
996996
});
997+
998+
it('should ignore badly escaped = characters', function() {
999+
expect(parseKeyValue('test=a=b')).toEqual({
1000+
'test': 'a=b'
1001+
});
1002+
});
9971003
});
9981004

9991005
describe('toKeyValue', function() {

0 commit comments

Comments
 (0)