Permalink
Browse files

Merge branch 'hotfix/3950'

Close #3950
Fixes #3851
  • Loading branch information...
2 parents 73708f0 + f6de952 commit 0191f1f738a76c40d8d24fb7f4ede7522f4dd47f @weierophinney weierophinney committed Mar 12, 2013
Showing with 25 additions and 8 deletions.
  1. +5 −4 library/Zend/Mvc/Router/Console/Simple.php
  2. +20 −4 tests/ZendTest/Mvc/Router/Console/SimpleTest.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];
@@ -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'),
@@ -159,6 +163,11 @@ public static function routeProvider()
'bar' => false
)
),
+ 'optional-long-flag-match-with-zero-value' => array(
+ '[--foo=]',
+ array('--foo=0'),
+ array('foo' => 0)
+ ),
'optional-long-value-flag' => array(
'--foo [--bar=]',
array('--foo', '--bar=4'),
@@ -583,7 +592,6 @@ public static function routeProvider()
'baz' => true
)
),
-
/*'combined-2' => array(
'--foo --bar',
array('a','b', 'c', '--foo', '--bar'),
@@ -600,7 +608,6 @@ public static function routeProvider()
);
}
-
/**
* @dataProvider routeProvider
* @param string $routeDefinition
@@ -629,6 +636,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
* @param Segment $route
@@ -664,7 +681,6 @@ public function __testParseExceptions($route, $exceptionName, $exceptionMessage)
new Simple($route);
}
-
public function testFactory()
{
$tester = new FactoryTester($this);

0 comments on commit 0191f1f

Please sign in to comment.