Skip to content

Commit

Permalink
fix($http): don't encode URL query substring "null" to "+"
Browse files Browse the repository at this point in the history
Fixes issue in encodeUriQuery used by $http and $resource that
treats null as a string and replaces the characters "null" with "+".
  • Loading branch information
Andrew-McLeod authored and IgorMinar committed Feb 27, 2013
1 parent c38c1c5 commit 86d191e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ function encodeUriQuery(val, pctEncodeSpaces) {
replace(/%3A/gi, ':').
replace(/%24/g, '$').
replace(/%2C/gi, ',').
replace((pctEncodeSpaces ? null : /%20/g), '+');
replace(/%20/g, (pctEncodeSpaces ? '%20' : '+'));
}


Expand Down
2 changes: 1 addition & 1 deletion src/ngResource/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,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) {
Expand Down
16 changes: 12 additions & 4 deletions test/AngularSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});

Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -741,11 +749,11 @@ describe('angular', function() {
describe('noConflict', function() {
var globalAngular;
beforeEach(function() {
globalAngular = angular;
globalAngular = angular;
});

afterEach(function() {
angular = globalAngular;
angular = globalAngular;
});

it('should return angular', function() {
Expand All @@ -757,7 +765,7 @@ describe('angular', function() {
var a = angular.noConflict();
expect(angular).toBeUndefined();
});

});

});
6 changes: 6 additions & 0 deletions test/ngResource/resourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ describe("resource", function() {
R.get({a: 'doh&foo', bar: ['baz1', 'baz2']});
});

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('{}');
Expand Down

0 comments on commit 86d191e

Please sign in to comment.