mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-08 23:04:45 +00:00
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 "+".
This commit is contained in:
parent
f98f8a3892
commit
b13da18e11
4 changed files with 17 additions and 3 deletions
|
|
@ -855,7 +855,7 @@ function encodeUriQuery(val, pctEncodeSpaces) {
|
||||||
replace(/%3A/gi, ':').
|
replace(/%3A/gi, ':').
|
||||||
replace(/%24/g, '$').
|
replace(/%24/g, '$').
|
||||||
replace(/%2C/gi, ',').
|
replace(/%2C/gi, ',').
|
||||||
replace((pctEncodeSpaces ? null : /%20/g), '+');
|
replace(/%20/g, (pctEncodeSpaces ? '%20' : '+'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -262,7 +262,7 @@ angular.module('ngResource', ['ng']).
|
||||||
replace(/%3A/gi, ':').
|
replace(/%3A/gi, ':').
|
||||||
replace(/%24/g, '$').
|
replace(/%24/g, '$').
|
||||||
replace(/%2C/gi, ',').
|
replace(/%2C/gi, ',').
|
||||||
replace((pctEncodeSpaces ? null : /%20/g), '+');
|
replace(/%20/g, (pctEncodeSpaces ? '%20' : '+'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function Route(template, defaults) {
|
function Route(template, defaults) {
|
||||||
|
|
|
||||||
|
|
@ -415,6 +415,14 @@ describe('angular', function() {
|
||||||
//encode ' ' as '%20' when a flag is used
|
//encode ' ' as '%20' when a flag is used
|
||||||
expect(encodeUriQuery(' ', true)).
|
expect(encodeUriQuery(' ', true)).
|
||||||
toEqual('%20%20');
|
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">');
|
toBe('<ng-abc x="2A">');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('startingTag', function() {
|
describe('startingTag', function() {
|
||||||
it('should allow passing in Nodes instead of Elements', function() {
|
it('should allow passing in Nodes instead of Elements', function() {
|
||||||
var txtNode = document.createTextNode('some text');
|
var txtNode = document.createTextNode('some text');
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,12 @@ describe("resource", function() {
|
||||||
R.get({a: 'doh@fo o', ':bar': '$baz@1', '!do&h': 'g=a h'});
|
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 () {
|
it('should allow relative paths in resource url', function () {
|
||||||
var R = $resource(':relativePath');
|
var R = $resource(':relativePath');
|
||||||
$httpBackend.expect('GET', 'data.json').respond('{}');
|
$httpBackend.expect('GET', 'data.json').respond('{}');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue