From ed7dca93fef3d74d87d74fd29283e42c405222e3 Mon Sep 17 00:00:00 2001 From: ephemeralsnow Date: Tue, 10 May 2016 19:59:21 +0900 Subject: [PATCH 1/3] Fixed 'Undefined index' --- library/Zend/Controller/Router/Route.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/Zend/Controller/Router/Route.php b/library/Zend/Controller/Router/Route.php index 927b97b3d3..361505ee98 100644 --- a/library/Zend/Controller/Router/Route.php +++ b/library/Zend/Controller/Router/Route.php @@ -324,8 +324,10 @@ public function match($path, $partial = false) if (!array_key_exists($var, $return)) { return false; } elseif ($return[$var] == '' || $return[$var] === null) { - // Empty variable? Replace with the default value. - $return[$var] = $this->_defaults[$var]; + if (array_key_exists($var, $this->_defaults)) { + // Empty variable? Replace with the default value. + $return[$var] = $this->_defaults[$var]; + } } } From 0e32fe675d1f332ed309efaedc16ded9fd0a77a7 Mon Sep 17 00:00:00 2001 From: ephemeralsnow Date: Thu, 12 May 2016 20:18:19 +0900 Subject: [PATCH 2/3] Add test --- tests/Zend/Controller/Router/Route/ChainTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/Zend/Controller/Router/Route/ChainTest.php b/tests/Zend/Controller/Router/Route/ChainTest.php index 95134cb104..3a0438c4d3 100644 --- a/tests/Zend/Controller/Router/Route/ChainTest.php +++ b/tests/Zend/Controller/Router/Route/ChainTest.php @@ -799,6 +799,19 @@ public function testChainingStaticDynamicMatchToDefaults() $this->assertEquals(0, $res['bar']); } + public function testChainingStaticDynamicMatchToNoDefaults() + { + $foo = new Zend_Controller_Router_Route_Static('foo'); + $bar = new Zend_Controller_Router_Route(':bar', array()); + $chain = $foo->chain($bar); + + $request = new Zend_Controller_Router_ChainTest_Request('http://www.zend.com/foo'); + $res = $chain->match($request); + + $this->assertTrue(is_array($res), 'Route did not match'); + $this->assertEquals('', $res['bar']); + } + /** * @group ZF-7368 */ From c19552b827d468aeebe9683afa3216981b9784cd Mon Sep 17 00:00:00 2001 From: ephemeralsnow Date: Thu, 12 May 2016 22:26:34 +0900 Subject: [PATCH 3/3] Change array_key_exists() to isset() --- library/Zend/Controller/Router/Route.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/Zend/Controller/Router/Route.php b/library/Zend/Controller/Router/Route.php index 361505ee98..52c850e9b9 100644 --- a/library/Zend/Controller/Router/Route.php +++ b/library/Zend/Controller/Router/Route.php @@ -324,7 +324,7 @@ public function match($path, $partial = false) if (!array_key_exists($var, $return)) { return false; } elseif ($return[$var] == '' || $return[$var] === null) { - if (array_key_exists($var, $this->_defaults)) { + if (isset($this->_defaults[$var])) { // Empty variable? Replace with the default value. $return[$var] = $this->_defaults[$var]; }