From e9ed8bf9c7bcb01f4d69e2c2884c7598595c72d4 Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Thu, 31 Jan 2019 19:35:38 -0500 Subject: [PATCH 1/2] Actually use result of array_unique This bug may have been harmless, the resulting regex would have been equivalent. Add simple test that parsing options with duplicates continues to succeed. (I didn't see any other tests of duplicates) Fixes #43 --- src/RouteMatcher/DefaultRouteMatcher.php | 8 ++++---- test/RouteMatcher/DefaultRouteMatcherTest.php | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/RouteMatcher/DefaultRouteMatcher.php b/src/RouteMatcher/DefaultRouteMatcher.php index 07ffbd5..5654e30 100644 --- a/src/RouteMatcher/DefaultRouteMatcher.php +++ b/src/RouteMatcher/DefaultRouteMatcher.php @@ -305,7 +305,7 @@ protected function parseDefinition($def) $options = preg_split('/ *\| */', trim($m['options']), 0, PREG_SPLIT_NO_EMPTY); // remove dupes - array_unique($options); + $options = array_unique($options); // prepare item $item = [ @@ -343,7 +343,7 @@ protected function parseDefinition($def) $options = preg_split('/ *\| */', trim($m['options']), 0, PREG_SPLIT_NO_EMPTY); // remove dupes - array_unique($options); + $options = array_unique($options); // prepare item $item = [ @@ -381,7 +381,7 @@ protected function parseDefinition($def) $options = preg_split('/ *\| */', trim($m['options']), 0, PREG_SPLIT_NO_EMPTY); // remove dupes - array_unique($options); + $options = array_unique($options); // remove prefix array_walk($options, function (&$val) { @@ -424,7 +424,7 @@ protected function parseDefinition($def) $options = preg_split('/ *\| */', trim($m['options']), 0, PREG_SPLIT_NO_EMPTY); // remove dupes - array_unique($options); + $options = array_unique($options); // remove prefix array_walk($options, function (&$val) { diff --git a/test/RouteMatcher/DefaultRouteMatcherTest.php b/test/RouteMatcher/DefaultRouteMatcherTest.php index 76c3287..fe48d8b 100644 --- a/test/RouteMatcher/DefaultRouteMatcherTest.php +++ b/test/RouteMatcher/DefaultRouteMatcherTest.php @@ -86,6 +86,15 @@ public static function routeProvider() ['--baz'], null ], + 'mandatory-long-flag-alternative-duplicates' => [ + '(--foo | --foo | --bar)', + ['--foo'], + [ + 'foo' => true, + 'bar' => false, + 'baz' => null, + ] + ], // -- mandatory short flags 'mandatory-short-flag-no-match' => [ @@ -375,6 +384,11 @@ public static function routeProvider() ['foo','bar'], ['foo' => null, 'altGroup' => 'bar', 'bar' => true, 'baz' => false] ], + 'mandatory-literal-namedAlternative-match-1-duplicates' => [ + 'foo ( bar | bar | baz ):altGroup', + ['foo','bar'], + ['foo' => null, 'altGroup' => 'bar', 'bar' => true, 'baz' => false] + ], 'mandatory-literal-namedAlternative-match-2' => [ 'foo ( bar | baz ):altGroup9', ['foo','baz'], From ae45d9a4a0501d43e4bfb27f7f97567ac41012f4 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 4 Feb 2019 13:46:03 -0600 Subject: [PATCH 2/2] Adds CHANGELOG entry for #44 --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0d0f3e..45afd11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,8 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed -- Nothing. +- [#44](https://github.com/zendframework/zend-console/pull/44) fixes usage of `array_unique()` within the `DefaultRouteMatcher` to + properly re-assign the array when invoked. ## 2.7.1 - TBD