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')
This commit is contained in:
Igor Minar 2011-12-12 13:38:50 -08:00
parent a4fe51da3b
commit 6d6f875345
2 changed files with 9 additions and 3 deletions

View file

@ -1,16 +1,15 @@
'use strict';
function Route(template, defaults) {
this.template = template = template + '#';
this.defaults = defaults || {};
var urlParams = this.urlParams = {};
forEach(template.split(/\W/), function(param){
if (param && template.match(new RegExp(":" + param + "\\W"))) {
if (param && template.match(new RegExp("[^\\\\]:" + param + "\\W"))) {
urlParams[param] = true;
}
});
this.template = template.replace(/\\:/g, ':');
}
Route.prototype = {

View file

@ -52,6 +52,13 @@ describe("resource", function() {
R.get({a:4, b:5, c:6});
}));
it('should support escaping collons in url template', inject(function($httpBackend) {
var R = resource.route('http://localhost\\:8080/Path/:a/\\:stillPath/:b');
$httpBackend.expect('GET', 'http://localhost:8080/Path/foo/:stillPath/bar').respond();
R.get({a: 'foo', b: 'bar'});
}));
it('should correctly encode url params', inject(function($httpBackend) {
var R = resource.route('/Path/:a');