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

Commit

Permalink
fix($resource): support escaping of ':' in resource url
Browse files Browse the repository at this point in the history
So one can how define cors/jsonp resources with port number as:

resource.route('http://localhost\\:8080/Path')
  • Loading branch information
IgorMinar committed Mar 20, 2012
1 parent a4fe51d commit 6d6f875
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Resource.js
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
7 changes: 7 additions & 0 deletions test/ResourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down

0 comments on commit 6d6f875

Please sign in to comment.