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

Commit

Permalink
fix(Angular): allow unescaped = signs in values in parseKeyValue
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Jochen Niebuhr authored and petebacondarwin committed Jul 27, 2015
1 parent 5298672 commit f13852c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Angular.js
Expand Up @@ -1250,13 +1250,19 @@ function tryDecodeURIComponent(value) {
* @returns {Object.<string,boolean|Array>}
*/
function parseKeyValue(/**string*/keyValue) {
var obj = {}, key_value, key;
var obj = {};
forEach((keyValue || "").split('&'), function(keyValue) {
var splitPoint, key, val;
if (keyValue) {
key_value = keyValue.replace(/\+/g,'%20').split('=');
key = tryDecodeURIComponent(key_value[0]);
key = keyValue = keyValue.replace(/\+/g,'%20');
splitPoint = keyValue.indexOf('=');
if (splitPoint !== -1) {
key = keyValue.substring(0, splitPoint);
val = keyValue.substring(splitPoint + 1);
}
key = tryDecodeURIComponent(key);
if (isDefined(key)) {
var val = isDefined(key_value[1]) ? tryDecodeURIComponent(key_value[1]) : true;
val = isDefined(val) ? tryDecodeURIComponent(val) : true;
if (!hasOwnProperty.call(obj, key)) {
obj[key] = val;
} else if (isArray(obj[key])) {
Expand Down
6 changes: 6 additions & 0 deletions test/AngularSpec.js
Expand Up @@ -994,6 +994,12 @@ describe('angular', function() {
'toString': '123'
});
});

it('should ignore badly escaped = characters', function() {
expect(parseKeyValue('test=a=b')).toEqual({
'test': 'a=b'
});
});
});

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

0 comments on commit f13852c

Please sign in to comment.