Skip to content

Commit

Permalink
makes route accept other deliminating tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
justinbmeyer committed May 16, 2012
1 parent cab9b51 commit ca98f8f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 4 additions & 3 deletions route/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ steal('can/observe', 'can/util/string/deparam', function() {
// Extract the variable names and replace with `RegExp` that will match
// an atual URL with values.
var names = [],
test = url.replace(matcher, function( whole, name ) {
names.push(name)
test = url.replace(matcher, function( whole, name, i ) {
names.push(name);
var next = "\\"+( url.substr(i+whole.length,1) || "&" )
// a name without a default value HAS to have a value
// a name that has a default value can be empty
// The `\\` is for string-escaping giving single `\` for `RegExp` escaping.
return "([^\\/\\&]"+(defaults[name] ? "*" : "+")+")"
return "([^" +next+"]"+(defaults[name] ? "*" : "+")+")"
});

// Add route in a form that can be easily figured out.
Expand Down
11 changes: 11 additions & 0 deletions route/route_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,14 @@ test("param order matching", function(){
equals(res,"/task2")
})

test("dashes in routes", function(){
can.route.routes = {};
can.route(":foo-:bar");

var obj = can.route.deparam("abc-def");
same(obj, {
foo : "abc",
bar : "def",
route: ":foo-:bar"
});
})

0 comments on commit ca98f8f

Please sign in to comment.