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

Commit 86d191e

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 c38c1c5 commit 86d191e

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

src/Angular.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ function encodeUriQuery(val, pctEncodeSpaces) {
875875
replace(/%3A/gi, ':').
876876
replace(/%24/g, '$').
877877
replace(/%2C/gi, ',').
878-
replace((pctEncodeSpaces ? null : /%20/g), '+');
878+
replace(/%20/g, (pctEncodeSpaces ? '%20' : '+'));
879879
}
880880

881881

src/ngResource/resource.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ angular.module('ngResource', ['ng']).
300300
replace(/%3A/gi, ':').
301301
replace(/%24/g, '$').
302302
replace(/%2C/gi, ',').
303-
replace((pctEncodeSpaces ? null : /%20/g), '+');
303+
replace(/%20/g, (pctEncodeSpaces ? '%20' : '+'));
304304
}
305305

306306
function Route(template, defaults) {

test/AngularSpec.js

+12-4
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');
@@ -741,11 +749,11 @@ describe('angular', function() {
741749
describe('noConflict', function() {
742750
var globalAngular;
743751
beforeEach(function() {
744-
globalAngular = angular;
752+
globalAngular = angular;
745753
});
746754

747755
afterEach(function() {
748-
angular = globalAngular;
756+
angular = globalAngular;
749757
});
750758

751759
it('should return angular', function() {
@@ -757,7 +765,7 @@ describe('angular', function() {
757765
var a = angular.noConflict();
758766
expect(angular).toBeUndefined();
759767
});
760-
768+
761769
});
762770

763771
});

test/ngResource/resourceSpec.js

+6
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ describe("resource", function() {
136136
R.get({a: 'doh&foo', bar: ['baz1', 'baz2']});
137137
});
138138

139+
it('should not encode string "null" to "+" in url params', function() {
140+
var R = $resource('/Path/:a');
141+
$httpBackend.expect('GET', '/Path/null').respond('{}');
142+
R.get({a: 'null'});
143+
});
144+
139145
it('should allow relative paths in resource url', function () {
140146
var R = $resource(':relativePath');
141147
$httpBackend.expect('GET', 'data.json').respond('{}');

0 commit comments

Comments
 (0)