Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/3950'
Browse files Browse the repository at this point in the history
Close #3950
Fixes #3851
  • Loading branch information
weierophinney committed Mar 12, 2013
2 parents 73708f0 + f6de952 commit 0191f1f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
9 changes: 5 additions & 4 deletions library/Zend/Mvc/Router/Console/Simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/**
Expand Down Expand Up @@ -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];

Expand Down
24 changes: 20 additions & 4 deletions tests/ZendTest/Mvc/Router/Console/SimpleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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'),
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -583,7 +592,6 @@ public static function routeProvider()
'baz' => true
)
),

/*'combined-2' => array(
'--foo --bar',
array('a','b', 'c', '--foo', '--bar'),
Expand All @@ -600,7 +608,6 @@ public static function routeProvider()
);
}


/**
* @dataProvider routeProvider
* @param string $routeDefinition
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -664,7 +681,6 @@ public function __testParseExceptions($route, $exceptionName, $exceptionMessage)
new Simple($route);
}


public function testFactory()
{
$tester = new FactoryTester($this);
Expand Down

0 comments on commit 0191f1f

Please sign in to comment.