Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b13da18

Browse files
Andrew-McLeodIgorMinar
authored andcommitted
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 "+".
1 parent f98f8a3 commit b13da18

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

src/Angular.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ function encodeUriQuery(val, pctEncodeSpaces) {
855855
replace(/%3A/gi, ':').
856856
replace(/%24/g, '$').
857857
replace(/%2C/gi, ',').
858-
replace((pctEncodeSpaces ? null : /%20/g), '+');
858+
replace(/%20/g, (pctEncodeSpaces ? '%20' : '+'));
859859
}
860860

861861

src/ngResource/resource.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ angular.module('ngResource', ['ng']).
262262
replace(/%3A/gi, ':').
263263
replace(/%24/g, '$').
264264
replace(/%2C/gi, ',').
265-
replace((pctEncodeSpaces ? null : /%20/g), '+');
265+
replace(/%20/g, (pctEncodeSpaces ? '%20' : '+'));
266266
}
267267

268268
function Route(template, defaults) {

test/AngularSpec.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,14 @@ describe('angular', function() {
415415
//encode ' ' as '%20' when a flag is used
416416
expect(encodeUriQuery(' ', true)).
417417
toEqual('%20%20');
418+
419+
//do not encode `null` as '+' when flag is used
420+
expect(encodeUriQuery('null', true)).
421+
toEqual('null');
422+
423+
//do not encode `null` with no flag
424+
expect(encodeUriQuery('null')).
425+
toEqual('null');
418426
});
419427
});
420428

@@ -673,7 +681,7 @@ describe('angular', function() {
673681
toBe('<ng-abc x="2A">');
674682
});
675683
});
676-
684+
677685
describe('startingTag', function() {
678686
it('should allow passing in Nodes instead of Elements', function() {
679687
var txtNode = document.createTextNode('some text');

test/ngResource/resourceSpec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ describe("resource", function() {
122122
R.get({a: 'doh@fo o', ':bar': '$baz@1', '!do&h': 'g=a h'});
123123
});
124124

125+
it('should not encode string "null" to "+" in url params', function() {
126+
var R = $resource('/Path/:a');
127+
$httpBackend.expect('GET', '/Path/null').respond('{}');
128+
R.get({a: 'null'});
129+
});
130+
125131
it('should allow relative paths in resource url', function () {
126132
var R = $resource(':relativePath');
127133
$httpBackend.expect('GET', 'data.json').respond('{}');

0 commit comments

Comments
 (0)