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

Commit 6d6f875

Browse files
committed
fix($resource): support escaping of ':' in resource url
So one can how define cors/jsonp resources with port number as: resource.route('http://localhost\\:8080/Path')
1 parent a4fe51d commit 6d6f875

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/Resource.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
'use strict';
22

3-
4-
53
function Route(template, defaults) {
64
this.template = template = template + '#';
75
this.defaults = defaults || {};
86
var urlParams = this.urlParams = {};
97
forEach(template.split(/\W/), function(param){
10-
if (param && template.match(new RegExp(":" + param + "\\W"))) {
8+
if (param && template.match(new RegExp("[^\\\\]:" + param + "\\W"))) {
119
urlParams[param] = true;
1210
}
1311
});
12+
this.template = template.replace(/\\:/g, ':');
1413
}
1514

1615
Route.prototype = {

test/ResourceSpec.js

+7
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ describe("resource", function() {
5252
R.get({a:4, b:5, c:6});
5353
}));
5454

55+
it('should support escaping collons in url template', inject(function($httpBackend) {
56+
var R = resource.route('http://localhost\\:8080/Path/:a/\\:stillPath/:b');
57+
58+
$httpBackend.expect('GET', 'http://localhost:8080/Path/foo/:stillPath/bar').respond();
59+
R.get({a: 'foo', b: 'bar'});
60+
}));
61+
5562
it('should correctly encode url params', inject(function($httpBackend) {
5663
var R = resource.route('/Path/:a');
5764

0 commit comments

Comments
 (0)