From 8d63c9a14e576ce386857c8baea1b67859d92189 Mon Sep 17 00:00:00 2001 From: Ben Scholzen Date: Thu, 29 Mar 2012 14:16:16 +0200 Subject: [PATCH] Fix parameter mapping problem when constraints contain parantheses --- library/Zend/Mvc/Router/Http/Segment.php | 10 ++++++---- tests/Zend/Mvc/Router/Http/SegmentTest.php | 6 ++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/library/Zend/Mvc/Router/Http/Segment.php b/library/Zend/Mvc/Router/Http/Segment.php index faa828f8930..ab743d8f1ae 100644 --- a/library/Zend/Mvc/Router/Http/Segment.php +++ b/library/Zend/Mvc/Router/Http/Segment.php @@ -211,15 +211,17 @@ protected function buildRegex(array $parts, array $constraints, &$groupIndex = 1 break; case 'parameter': + $groupName = '?P'; + 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': diff --git a/tests/Zend/Mvc/Router/Http/SegmentTest.php b/tests/Zend/Mvc/Router/Http/SegmentTest.php index 28c6f635997..54f275be88f 100644 --- a/tests/Zend/Mvc/Router/Http/SegmentTest.php +++ b/tests/Zend/Mvc/Router/Http/SegmentTest.php @@ -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')), '/',