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

Commit 60af504

Browse files
Carlo s A. Guillenbtford
Carlo s A. Guillen
authored andcommitted
fix($location): handle plus character in query strings
Closes #3042
1 parent 243d9ac commit 60af504

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Angular.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ function parseKeyValue(/**string*/keyValue) {
11131113
var obj = {}, key_value, key;
11141114
forEach((keyValue || "").split('&'), function(keyValue) {
11151115
if ( keyValue ) {
1116-
key_value = keyValue.split('=');
1116+
key_value = keyValue.replace(/\+/g,'%20').split('=');
11171117
key = tryDecodeURIComponent(key_value[0]);
11181118
if ( isDefined(key) ) {
11191119
var val = isDefined(key_value[1]) ? tryDecodeURIComponent(key_value[1]) : true;

test/ng/locationSpec.js

+12
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,18 @@ describe('$location', function() {
323323
expect(url.search()).toEqual({'i j': '<>#'});
324324
expect(url.hash()).toBe('x <>#');
325325
});
326+
327+
it('should decode pluses as spaces in urls', function() {
328+
url = new LocationHtml5Url('http://host.com/');
329+
url.$$parse('http://host.com/?a+b=c+d');
330+
expect(url.search()).toEqual({'a b':'c d'});
331+
});
332+
333+
it('should retain pluses when setting search queries', function() {
334+
url.search({'a+b':'c+d'});
335+
expect(url.search()).toEqual({'a+b':'c+d'});
336+
});
337+
326338
});
327339
});
328340

0 commit comments

Comments
 (0)