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

Fixed console routes when using same name for group and parameter #4262

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions library/Zend/Mvc/Router/Console/Simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -692,17 +692,17 @@ public function match(Request $request, $pathOffset = null)
if (isset($part['alternatives'])) {
if ($part['hasValue']) {
foreach ($part['alternatives'] as $alt) {
if ($alt == $matchedName) {
if ($alt === $matchedName && !isset($matches[$alt])) {
$matches[$alt] = $value;
} else {
} elseif (!isset($matches[$alt])) {
$matches[$alt] = null;
}
}
} else {
foreach ($part['alternatives'] as $alt) {
if ($alt == $matchedName) {
if ($alt === $matchedName && !isset($matches[$alt])) {
$matches[$alt] = true;
} else {
} elseif (!isset($matches[$alt])) {
$matches[$alt] = false;
}
}
Expand Down
77 changes: 77 additions & 0 deletions tests/ZendTest/Mvc/Router/Console/SimpleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,83 @@ public static function routeProvider()
'baz' => true
)
),
// group with group name diferent than options (short)
'group-1' => array(
'group [-t|--test]:testgroup',
array('group', '-t'),
array(
'group' => true,
'testgroup' => true,
)
),
// group with group name diferent than options (long)
'group-2' => array(
'group [-t|--test]:testgroup',
array('group', '--test'),
array(
'group' => true,
'testgroup' => true,
)
),
// group with same name as option (short)
'group-3' => array(
'group [-t|--test]:test',
array('group', '-t'),
array(
'group' => true,
'test' => true,
)
),
// group with same name as option (long)
'group-4' => array(
'group [-t|--test]:test',
array('group', '--test'),
array(
'group' => true,
'test' => true,
)
),
'group-5' => array(
'group (-t | --test ):test',
array('group', '--test'),
array(
'group' => true,
'test' => true,
),
),
'group-6' => array(
'group (-t | --test ):test',
array('group', '-t'),
array(
'group' => true,
'test' => true,
),
),
'group-7' => array(
'group [-x|-y|-z]:test',
array('group', '-y'),
array(
'group' => true,
'test' => true,
),
),
'group-8' => array(
'group [--foo|--bar|--baz]:test',
array('group', '--foo'),
array(
'group' => true,
'test' => true,
),
),
'group-9' => array(
'group (--foo|--bar|--baz):test',
array('group', '--foo'),
array(
'group' => true,
'test' => true,
),
),

/*'combined-2' => array(
'--foo --bar',
array('a','b', 'c', '--foo', '--bar'),
Expand Down