From 7a51138ed998e2dfcb3ffb51d65ad3ef5248d9cc Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 6 Aug 2011 18:15:37 -0400 Subject: [PATCH] Special case the empty rule. --- http/url_map.php | 8 ++++++++ testing/tests/http/url_map_test.php | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/http/url_map.php b/http/url_map.php index 8df90e8..fac6a42 100644 --- a/http/url_map.php +++ b/http/url_map.php @@ -103,6 +103,14 @@ class UrlMap $path_length = strlen($request->url); foreach ($this->map as $rule => $action) { + // First check if this is the empty rule. + if (empty($rule)) { + if (empty($request->url)) + return $action; + else + continue; + } + // Check if this is a regular expression rule and match it. if ($rule[0] == '/' && substr($rule, -1) == '/') { $matches = array(); diff --git a/testing/tests/http/url_map_test.php b/testing/tests/http/url_map_test.php index afe5436..722eb32 100644 --- a/testing/tests/http/url_map_test.php +++ b/testing/tests/http/url_map_test.php @@ -74,6 +74,25 @@ class UrlMapTest extends \PHPUnit_Framework_TestCase $this->assertEquals('Second', $this->fixture->Evaluate($request)); } + public function testEmptyRule() + { + $map = array( + 'some/first' => 'First', + '' => 'Index', + 'some/second' => 'Second' + ); + $this->fixture->set_map($map); + + $request = new http\Request('some/first'); + $this->assertEquals('First', $this->fixture->Evaluate($request)); + + $request = new http\Request(''); + $this->assertEquals('Index', $this->fixture->Evaluate($request)); + + $request = new http\Request('some/second'); + $this->assertEquals('Second', $this->fixture->Evaluate($request)); + } + public function testExtractSingle() { $map = array( -- 2.22.5