Permalink
Browse files

Fixing regexp routes that fail if captures are unnamed. [#8 state:res…

…olved]

Update matching test case.
  • Loading branch information...
Fabrice Luraine
Fabrice Luraine committed Jun 9, 2009
1 parent 8f96b2b commit 166f93c254906720afcb21418fe89c0bc637f9ea
Showing with 13 additions and 4 deletions.
  1. +7 −2 lib/limonade.php
  2. +6 −2 tests/router.php
View
@@ -1112,13 +1112,18 @@ function route_find($method, $path)
{
array_shift($matches);
$n_matches = count($matches);
$n_names = count($route["names"]);
$names = array_values($route["names"]);
$n_names = count($names);
if( $n_matches < $n_names )
{
$a = array_fill(0, $n_names - $n_matches, null);
$matches = array_merge($matches, $a);
}
$params = array_combine(array_values($route["names"]), $matches);
else if( $n_matches > $n_names )
{
$names = range($n_names, $n_matches - 1);
}
$params = array_combine($names, $matches);
}
$route["params"] = $params;
return $route;
View
@@ -174,9 +174,10 @@ function test_router_find_route()
route( "get", "/edit/:id", "my_edit_func" );
route( "put", "/update/:id", "my_update_func" );
route( "delete", "/delete/:id", "my_delete_func" );
route( "get", "^/list/(\d+)","my_list_func" );
$routes = route( "get", "/*.jpg/:size","my_jpeg" );
assert_length_of($routes, 7);
assert_length_of($routes, 8);
$r = route_find("GET", "/unkown");
assert_false($r);
@@ -203,7 +204,7 @@ function test_router_find_route()
route( "get", "/index/*", "my_index_func2" );
$routes = route( "delete", "/delete/:id/:confirm", "my_delete_func2" );
assert_length_of($routes, 9);
assert_length_of($routes, 10);
$r = route_find("GET", "/index");
assert_equal($r["function"], "my_index_func");
@@ -219,6 +220,9 @@ function test_router_find_route()
$r = route_find("DELETE", "/delete/120/ok");
assert_equal($r["function"], "my_delete_func2");
$r = route_find("GET", "/list/120");
assert_equal($r["function"], "my_list_func");
}
endtests();

0 comments on commit 166f93c

Please sign in to comment.