Fix zero value in argument #3950

Closed
wants to merge 2 commits into
from
View
9 library/Zend/Mvc/Router/Console/Simple.php
@@ -557,10 +557,11 @@ public function match(Request $request, $pathOffset = null)
*/
$positional = $named = array();
foreach ($this->parts as &$part) {
- if ($part['positional'])
+ if ($part['positional']) {
$positional[] = &$part;
- else
+ } else {
$named[] = &$part;
+ }
}
/**
@@ -651,8 +652,8 @@ public function match(Request $request, $pathOffset = null)
/**
* Try to retrieve value if it is expected
*/
- if (!$value && $part['hasValue']) {
- if ($x < count($params)+1) {
+ if ((null === $value || "" === $value) && $part['hasValue']) {
+ if ($x < count($params)+1 && isset($params[$x])) {
// retrieve value from adjacent param
$value = $params[$x];
View
23 tests/ZendTest/Mvc/Router/Console/SimpleTest.php
@@ -2,7 +2,6 @@
namespace ZendTest\Mvc\Router\Console;
use PHPUnit_Framework_TestCase as TestCase;
-use Zend\Http\Request;
use Zend\Console\Request as ConsoleRequest;
use Zend\Mvc\Router\Console\Simple;
use ZendTest\Mvc\Router\FactoryTester;
@@ -28,6 +27,11 @@ public static function routeProvider()
array('--foo','--bar'),
array('foo' => true, 'bar' => true)
),
+ 'mandatory-long-flag-match-with-zero-value' => array(
+ '--foo=',
+ array('--foo=0'),
+ array('foo' => 0)
+ ),
'mandatory-long-flag-mixed-order-match' => array(
'--foo --bar',
array('--bar','--foo'),
@@ -583,7 +587,6 @@ public static function routeProvider()
'baz' => true
)
),
-
/*'combined-2' => array(
'--foo --bar',
array('a','b', 'c', '--foo', '--bar'),
@@ -599,8 +602,7 @@ public static function routeProvider()
);
}
-
-
+
/**
* @dataProvider routeProvider
* @param string $routeDefinition
@@ -628,6 +630,16 @@ public function testMatching($routeDefinition, array $arguments = array(), array
}
}
}
+
+ public function testCanNotMatchingWithEmtpyMandatoryParam()
+ {
+ $arguments = array('--foo=');
+ array_unshift($arguments,'scriptname.php');
+ $request = new ConsoleRequest($arguments);
+ $route = new Simple('--foo=');
+ $match = $route->match($request);
+ $this->assertEquals(null, $match);
+ }
/**
* @dataProvider routeProvider
@@ -663,8 +675,7 @@ public function __testParseExceptions($route, $exceptionName, $exceptionMessage)
$this->setExpectedException($exceptionName, $exceptionMessage);
new Simple($route);
}
-
-
+
public function testFactory()
{
$tester = new FactoryTester($this);