Permalink
Browse files

fix params

  • Loading branch information...
1 parent dc41546 commit 8750b3bfb1cbb294a32326c3bbe66fc8c4b67e27 @jankuca committed Apr 9, 2012
Showing with 16 additions and 4 deletions.
  1. +16 −4 src/modules/router.js
View
@@ -92,13 +92,17 @@ var Router = module.exports.Router = Function.inherit(function () {
params = {},
param_keys = [],
rules,
+ unmatched_rules,
key;
-
+
Object.getOwnPropertyNames(route[2]).forEach(function (key) {
options[key] = route[2][key];
});
rules = options.params;
+ if (rules && rules instanceof RegExp === false) {
+ unmatched_rules = JSON.parse('{"' + Object.keys(rules).join('":1,"') + '":1}');
+ }
if (placeholders !== null) {
placeholders.forEach(function (placeholder) {
@@ -129,10 +133,13 @@ var Router = module.exports.Router = Function.inherit(function () {
} else {
if (Object.getOwnPropertyNames(rules).some(function (key) {
var index = param_keys.indexOf(key);
- if (index === -1 || !rules[key].test(match[index + 1])) {
- return true;
+ if (index !== -1) {
+ if (!rules[key].test(match[index + 1])) {
+ return true;
+ }
+ params[key] = match[index + 1];
+ delete unmatched_rules[key];
}
- params[key] = match[index + 1];
})) {
return;
}
@@ -175,12 +182,17 @@ var Router = module.exports.Router = Function.inherit(function () {
return true;
}
params[key] = query[key];
+ delete unmatched_rules[key];
})) {
return;
}
}
}
+ if (unmatched_rules && Object.keys(unmatched_rules).length !== 0) {
+ return;
+ }
+
result = {
'static': false,
'namespace': route[0],

0 comments on commit 8750b3b

Please sign in to comment.