Skip to content

Commit

Permalink
Merge remote-tracking branch 'DASPRiD/hotfix/segment-constraints-para…
Browse files Browse the repository at this point in the history
…ntheses'
  • Loading branch information
EvanDotPro committed Mar 29, 2012
2 parents 8cb9622 + 8d63c9a commit 9f60857
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 6 additions & 4 deletions library/Zend/Mvc/Router/Http/Segment.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,17 @@ protected function buildRegex(array $parts, array $constraints, &$groupIndex = 1
break;

case 'parameter':
$groupName = '?P<param' . $groupIndex . '>';

if (isset($constraints[$part[1]])) {
$regex .= '(' . $constraints[$part[1]] . ')';
$regex .= '(' . $groupName . $constraints[$part[1]] . ')';
} elseif ($part[2] === null) {
$regex .= '([^/]+)';
$regex .= '(' . $groupName . '[^/]+)';
} else {
$regex .= '([^' . $part[2] . ']+)';
$regex .= '(' . $groupName . '[^' . $part[2] . ']+)';
}

$this->paramMap[$groupIndex++] = $part[1];
$this->paramMap['param' . $groupIndex++] = $part[1];
break;

case 'optional':
Expand Down
6 changes: 6 additions & 0 deletions tests/Zend/Mvc/Router/Http/SegmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ public static function routeProvider()
null,
array('foo' => 'foo-bar')
),
'constraints-with-parantheses-dont-break-parameter-map' => array(
new Segment('/:foo/:bar', array('foo' => '(bar)')),
'/bar/baz',
null,
array('foo' => 'bar', 'bar' => 'baz')
),
'simple-match-with-optional-parameter' => array(
new Segment('/[:foo]', array(), array('foo' => 'bar')),
'/',
Expand Down

0 comments on commit 9f60857

Please sign in to comment.