From 0a627859864660ecfc2fc3bc3931c5c74d20aea0 Mon Sep 17 00:00:00 2001
From: "Carlo s A. Guillen" <caguillen@google.com>
Date: Thu, 17 Jul 2014 14:47:14 -0700
Subject: [PATCH] fix($location): handle plus character in query strings

Closes #3042
---
 src/Angular.js          |  2 +-
 test/ng/locationSpec.js | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/Angular.js b/src/Angular.js
index dd64e22d5ba5..20f8ce123343 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -1099,7 +1099,7 @@ function parseKeyValue(/**string*/keyValue) {
   var obj = {}, key_value, key;
   forEach((keyValue || "").split('&'), function(keyValue) {
     if ( keyValue ) {
-      key_value = keyValue.split('=');
+      key_value = keyValue.replace(/\+/g,'%20').split('=');
       key = tryDecodeURIComponent(key_value[0]);
       if ( isDefined(key) ) {
         var val = isDefined(key_value[1]) ? tryDecodeURIComponent(key_value[1]) : true;
diff --git a/test/ng/locationSpec.js b/test/ng/locationSpec.js
index 83a5291b157d..7e842e16a749 100644
--- a/test/ng/locationSpec.js
+++ b/test/ng/locationSpec.js
@@ -323,6 +323,18 @@ describe('$location', function() {
         expect(url.search()).toEqual({'i j': '<>#'});
         expect(url.hash()).toBe('x <>#');
       });
+
+      it('should decode pluses as spaces in urls', function() {
+        url = new LocationHtml5Url('http://host.com/');
+        url.$$parse('http://host.com/?a+b=c+d');
+        expect(url.search()).toEqual({'a b':'c d'});
+      });
+
+      it('should retain pluses when setting search queries', function() {
+        url.search({'a+b':'c+d'});
+        expect(url.search()).toEqual({'a+b':'c+d'});
+      });
+
     });
   });