Permalink
Browse files

makes route accept other deliminating tokens

  • Loading branch information...
justinbmeyer committed May 16, 2012
1 parent cab9b51 commit ca98f8f2b781456a42866805e6f9879899dc38af
Showing with 15 additions and 3 deletions.
  1. +4 −3 route/route.js
  2. +11 −0 route/route_test.js
View
@@ -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.
View
@@ -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.