Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
wants to merge 2 commits into from

4 participants

@al-the-x

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 @ OrlandoPHP.org

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".
9cc2133
@al-the-x al-the-x This is an example from production that broke with the previous behav…
…ior, provided for clarity.
24f0d01
@al-the-x

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.

@mehlah

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

@mehlah

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

@mehlah

@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
@al-the-x

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...?

@nateabele
Owner

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.

@al-the-x

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

@nateabele
Owner

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
View
2  net/http/Route.php
@@ -396,7 +396,7 @@ public function compile() {
return;
}
$this->_pattern = "@^{$this->_template}\$@";
- $match = '@([/.])?\{:([^:}]+):?((?:[^{]+(?:\{[0-9,]+\})?)*)\}@S';
+ $match = '@([/.])?\{:([^:}]+):?((?:[^{]+(?:\{[0-9,]+\})?)*?)\}@S';
preg_match_all($match, $this->_pattern, $m);
if (!$tokens = $m[0]) {
View
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.