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

Commit 39a90a9

Browse files
vteremasovgkalpak
vteremasov
authored andcommitted
fix($resource): correctly unescape /\. even if \. comes from a param value
Closes #15627
1 parent fd4f011 commit 39a90a9

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/ngResource/resource.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -590,11 +590,12 @@ angular.module('ngResource', ['ng']).
590590
url = url.replace(/\/+$/, '') || '/';
591591
}
592592

593-
// then replace collapse `/.` if found in the last URL path segment before the query
594-
// E.g. `http://url.com/id./format?q=x` becomes `http://url.com/id.format?q=x`
593+
// Collapse `/.` if found in the last URL path segment before the query.
594+
// E.g. `http://url.com/id/.format?q=x` becomes `http://url.com/id.format?q=x`.
595595
url = url.replace(/\/\.(?=\w+($|\?))/, '.');
596-
// replace escaped `/\.` with `/.`
597-
config.url = protocolAndIpv6 + url.replace(/\/\\\./, '/.');
596+
// Replace escaped `/\.` with `/.`.
597+
// (If `\.` comes from a param value, it will be encoded as `%5C.`.)
598+
config.url = protocolAndIpv6 + url.replace(/\/(\\|%5C)\./, '/.');
598599

599600

600601
// set params - delegate param encoding to $http

test/ngResource/resourceSpec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,18 @@ describe('basic usage', function() {
14561456
$httpBackend.expect('POST', '/users/.json').respond();
14571457
$resource('/users/\\.json').save({});
14581458
});
1459+
it('should work with save() if dynamic params', function() {
1460+
$httpBackend.expect('POST', '/users/.json').respond();
1461+
$resource('/users/:json', {json: '\\.json'}).save({});
1462+
});
1463+
it('should work with query() if dynamic params', function() {
1464+
$httpBackend.expect('GET', '/users/.json').respond();
1465+
$resource('/users/:json', {json: '\\.json'}).query();
1466+
});
1467+
it('should work with get() if dynamic params', function() {
1468+
$httpBackend.expect('GET', '/users/.json').respond();
1469+
$resource('/users/:json', {json: '\\.json'}).get();
1470+
});
14591471
});
14601472
});
14611473

0 commit comments

Comments
 (0)