From 6d6f875345e01f2c6c63ef95164f6f39e923da15 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Mon, 12 Dec 2011 13:38:50 -0800 Subject: [PATCH] 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') --- src/Resource.js | 5 ++--- test/ResourceSpec.js | 7 +++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Resource.js b/src/Resource.js index 3b4a6db1b522..64c8c159a4b4 100644 --- a/src/Resource.js +++ b/src/Resource.js @@ -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 = { diff --git a/test/ResourceSpec.js b/test/ResourceSpec.js index 7ee7aec8899d..29bdad75fb05 100644 --- a/test/ResourceSpec.js +++ b/test/ResourceSpec.js @@ -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');