fix($resource): correctly unescape /\. even if \. comes from a param value

Closes #15627
This commit is contained in:
vteremasov
2017-01-19 19:09:34 +03:00
committed by Georgios Kalpakas
parent fd4f011118
commit 39a90a9c20
2 changed files with 17 additions and 4 deletions
+5 -4
View File
@@ -590,11 +590,12 @@ angular.module('ngResource', ['ng']).
url = url.replace(/\/+$/, '') || '/';
}
// then replace collapse `/.` if found in the last URL path segment before the query
// E.g. `http://url.com/id./format?q=x` becomes `http://url.com/id.format?q=x`
// Collapse `/.` if found in the last URL path segment before the query.
// E.g. `http://url.com/id/.format?q=x` becomes `http://url.com/id.format?q=x`.
url = url.replace(/\/\.(?=\w+($|\?))/, '.');
// replace escaped `/\.` with `/.`
config.url = protocolAndIpv6 + url.replace(/\/\\\./, '/.');
// Replace escaped `/\.` with `/.`.
// (If `\.` comes from a param value, it will be encoded as `%5C.`.)
config.url = protocolAndIpv6 + url.replace(/\/(\\|%5C)\./, '/.');
// set params - delegate param encoding to $http
+12
View File
@@ -1456,6 +1456,18 @@ describe('basic usage', function() {
$httpBackend.expect('POST', '/users/.json').respond();
$resource('/users/\\.json').save({});
});
it('should work with save() if dynamic params', function() {
$httpBackend.expect('POST', '/users/.json').respond();
$resource('/users/:json', {json: '\\.json'}).save({});
});
it('should work with query() if dynamic params', function() {
$httpBackend.expect('GET', '/users/.json').respond();
$resource('/users/:json', {json: '\\.json'}).query();
});
it('should work with get() if dynamic params', function() {
$httpBackend.expect('GET', '/users/.json').respond();
$resource('/users/:json', {json: '\\.json'}).get();
});
});
});