Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


When there are only two simple parameters, routing fails... #162

wants to merge 2 commits into from

4 participants


I added a test to lithium/tests/cases/net/http/RouteTest.php to reflect a route that we were attempting to use in our project that was failing to route. My guess is that the regex in Route::compile():366 is incorrectly seeing the second pattern as the regex part of the first pattern. I made that capture pattern lazy and got greens. Please review. Thanks,

David @

al-the-x added some commits
@al-the-x al-the-x Making the capture pattern lazy for the optional regex part fixes cer…
…tain routes, i.e. "/personnel/{:personnel_id}/position/{:position_id}/action/create".
@al-the-x al-the-x This is an example from production that broke with the previous behav…
…ior, provided for clarity.

BTW, I rebased to the current (as of today) master after making that pull request, which of course changed my commits. If github doesn't know what to do with it, I'll reopen my pull request.


This is related to issue #157 #154
and solve it !
I was completely on the wrong track with my solution

more tests cases here mehlah@33089d4


Is there a regex master who can explain why this happens and what's exactly going on ? :-)


@ifunk: sure, I understand the role played by the ? in the regex, but how come increasing pcre backtrack_limit make it as well ?
That's the part I don't get :-)

@nateabele nateabele closed this

Since you essentially used the code from this pull request in your own commit verbatim, wouldn't it have been easier just to accept the pull request? Or am I missing some contributor politics here...?


Sorry, it was mostly laziness. The fix itself was the same, but I ended up completely rewriting the test to be exhaustive in terms of the cases it covers. Anyway, I couldn't remember the series of commands to amend someone else's work but still maintain attribution.


See git commit --amend [commit-ish] for future reference... ;)


Heh, nice. Thanks.

@smergler smergler referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 17, 2011
  1. @al-the-x

    Making the capture pattern lazy for the optional regex part fixes cer…

    al-the-x authored al-the-x committed
    …tain routes, i.e. "/personnel/{:personnel_id}/position/{:position_id}/action/create".
  2. @al-the-x

    This is an example from production that broke with the previous behav…

    al-the-x authored al-the-x committed
    …ior, provided for clarity.
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 2 deletions.
  1. +1 −1  net/http/Route.php
  2. +16 −1 tests/cases/net/http/RouteTest.php
2  net/http/Route.php
@@ -396,7 +396,7 @@ public function compile() {
$this->_pattern = "@^{$this->_template}\$@";
- $match = '@([/.])?\{:([^:}]+):?((?:[^{]+(?:\{[0-9,]+\})?)*)\}@S';
+ $match = '@([/.])?\{:([^:}]+):?((?:[^{]+(?:\{[0-9,]+\})?)*?)\}@S';
preg_match_all($match, $this->_pattern, $m);
if (!$tokens = $m[0]) {
17 tests/cases/net/http/RouteTest.php
@@ -559,6 +559,21 @@ public function testContinuationRoute() {
$result = $route->match(array('admin' => true, 'args' => ''));
$this->assertEqual('/admin/{:args}', $result);
+ }
+ public function testTwoParameterRoutes ( ) {
+ $route = new Route(array(
+ 'template' => '/personnel/{:personnel_id}/position/{:position_id}/actions/create',
+ 'params' => array('controller' => 'actions', 'action' => 'create'),
+ ));
+ $route->compile();
+ $data = $route->export(); $actual = $data['pattern'];
+ $expected = '@^/personnel(?:/(?P<personnel_id>[^\\/]+))/position(?:/(?P<position_id>[^\\/]+))/actions/create$@';
+ $this->assertEqual($expected, $actual);
public function testContinuationRouteWithParameters() {
@@ -592,4 +607,4 @@ public function testContinuationRouteWithQueryString() {
Something went wrong with that request. Please try again.