Skip to content

Commit ca98f8f

Browse files
committed
makes route accept other deliminating tokens
1 parent cab9b51 commit ca98f8f

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

route/route.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,13 @@ steal('can/observe', 'can/util/string/deparam', function() {
5959
// Extract the variable names and replace with `RegExp` that will match
6060
// an atual URL with values.
6161
var names = [],
62-
test = url.replace(matcher, function( whole, name ) {
63-
names.push(name)
62+
test = url.replace(matcher, function( whole, name, i ) {
63+
names.push(name);
64+
var next = "\\"+( url.substr(i+whole.length,1) || "&" )
6465
// a name without a default value HAS to have a value
6566
// a name that has a default value can be empty
6667
// The `\\` is for string-escaping giving single `\` for `RegExp` escaping.
67-
return "([^\\/\\&]"+(defaults[name] ? "*" : "+")+")"
68+
return "([^" +next+"]"+(defaults[name] ? "*" : "+")+")"
6869
});
6970

7071
// Add route in a form that can be easily figured out.

route/route_test.js

+11
Original file line numberDiff line numberDiff line change
@@ -407,3 +407,14 @@ test("param order matching", function(){
407407
equals(res,"/task2")
408408
})
409409

410+
test("dashes in routes", function(){
411+
can.route.routes = {};
412+
can.route(":foo-:bar");
413+
414+
var obj = can.route.deparam("abc-def");
415+
same(obj, {
416+
foo : "abc",
417+
bar : "def",
418+
route: ":foo-:bar"
419+
});
420+
})

0 commit comments

Comments
 (0)