aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew McLeod2013-02-25 21:25:18 -0800
committerIgor Minar2013-02-26 17:29:08 -0800
commitb13da18e11d5f67696906d1ecd2fc9e753d50da4 (patch)
treee3dbb159ec82c59d290b68a541078fa85a6ffdaf
parentf98f8a3892874382efbd42eded01c94c76188e56 (diff)
downloadangular.js-b13da18e11d5f67696906d1ecd2fc9e753d50da4.tar.bz2
fix($http): don't encode URL query substring "null" to "+"
Fixes issue in encodeUriQuery used by $http and $resource that treats null as a string and replaces the characters "null" with "+".
-rw-r--r--src/Angular.js2
-rw-r--r--src/ngResource/resource.js2
-rw-r--r--test/AngularSpec.js10
-rw-r--r--test/ngResource/resourceSpec.js6
4 files changed, 17 insertions, 3 deletions
diff --git a/src/Angular.js b/src/Angular.js
index 5195489e..93e4f6af 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -855,7 +855,7 @@ function encodeUriQuery(val, pctEncodeSpaces) {
replace(/%3A/gi, ':').
replace(/%24/g, '$').
replace(/%2C/gi, ',').
- replace((pctEncodeSpaces ? null : /%20/g), '+');
+ replace(/%20/g, (pctEncodeSpaces ? '%20' : '+'));
}
diff --git a/src/ngResource/resource.js b/src/ngResource/resource.js
index eac77603..a05e3598 100644
--- a/src/ngResource/resource.js
+++ b/src/ngResource/resource.js
@@ -262,7 +262,7 @@ angular.module('ngResource', ['ng']).
replace(/%3A/gi, ':').
replace(/%24/g, '$').
replace(/%2C/gi, ',').
- replace((pctEncodeSpaces ? null : /%20/g), '+');
+ replace(/%20/g, (pctEncodeSpaces ? '%20' : '+'));
}
function Route(template, defaults) {
diff --git a/test/AngularSpec.js b/test/AngularSpec.js
index e734decf..c535bf12 100644
--- a/test/AngularSpec.js
+++ b/test/AngularSpec.js
@@ -415,6 +415,14 @@ describe('angular', function() {
//encode ' ' as '%20' when a flag is used
expect(encodeUriQuery(' ', true)).
toEqual('%20%20');
+
+ //do not encode `null` as '+' when flag is used
+ expect(encodeUriQuery('null', true)).
+ toEqual('null');
+
+ //do not encode `null` with no flag
+ expect(encodeUriQuery('null')).
+ toEqual('null');
});
});
@@ -673,7 +681,7 @@ describe('angular', function() {
toBe('<ng-abc x="2A">');
});
});
-
+
describe('startingTag', function() {
it('should allow passing in Nodes instead of Elements', function() {
var txtNode = document.createTextNode('some text');
diff --git a/test/ngResource/resourceSpec.js b/test/ngResource/resourceSpec.js
index bfed3082..768ffd77 100644
--- a/test/ngResource/resourceSpec.js
+++ b/test/ngResource/resourceSpec.js
@@ -122,6 +122,12 @@ describe("resource", function() {
R.get({a: 'doh@fo o', ':bar': '$baz@1', '!do&h': 'g=a h'});
});
+ it('should not encode string "null" to "+" in url params', function() {
+ var R = $resource('/Path/:a');
+ $httpBackend.expect('GET', '/Path/null').respond('{}');
+ R.get({a: 'null'});
+ });
+
it('should allow relative paths in resource url', function () {
var R = $resource(':relativePath');
$httpBackend.expect('GET', 'data.json').respond('{}');