From f1b16fc82d69410feed7001346161a4093cc6384 Mon Sep 17 00:00:00 2001 From: Chris W Jones Date: Tue, 26 Apr 2022 14:38:09 -0400 Subject: [PATCH 1/2] Check for empty Tag filter string If the `filterString` in `TagFilter` is an empty string, an exception was being thrown because the code was expecting a non-empty string. This checks if the string is non-empty and returns early if it is. Issue: #250 --- src/Behat/Gherkin/Filter/TagFilter.php | 5 +++++ tests/Behat/Gherkin/Filter/TagFilterTest.php | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/src/Behat/Gherkin/Filter/TagFilter.php b/src/Behat/Gherkin/Filter/TagFilter.php index 579ed4e8..5936bc2b 100644 --- a/src/Behat/Gherkin/Filter/TagFilter.php +++ b/src/Behat/Gherkin/Filter/TagFilter.php @@ -13,6 +13,7 @@ use Behat\Gherkin\Node\FeatureNode; use Behat\Gherkin\Node\OutlineNode; use Behat\Gherkin\Node\ScenarioInterface; +use function mb_strlen; /** * Filters scenarios by feature/scenario tag. @@ -137,6 +138,10 @@ protected function isTagsMatchCondition($tags) { $satisfies = true; + if (mb_strlen($this->filterString) === 0) { + return $satisfies; + } + foreach (explode('&&', $this->filterString) as $andTags) { $satisfiesComma = false; diff --git a/tests/Behat/Gherkin/Filter/TagFilterTest.php b/tests/Behat/Gherkin/Filter/TagFilterTest.php index 27211523..99b72c3d 100644 --- a/tests/Behat/Gherkin/Filter/TagFilterTest.php +++ b/tests/Behat/Gherkin/Filter/TagFilterTest.php @@ -280,4 +280,13 @@ public function testFilterWithWhitespaceIsDeprecated() $this->assertEquals([$scenario], $scenarios); } + + public function testTagFilterThatIsAllWhitespaceIsIgnored() + { + $feature = new FeatureNode(null, null, [], null, [], null, null, null, 1); + $tagFilter = new TagFilter(''); + $result = $tagFilter->isFeatureMatch($feature); + + $this->assertTrue($result); + } } From 3036a8769c0a16cc54a4d8f9ed0662770ff1b6a3 Mon Sep 17 00:00:00 2001 From: Chris W Jones Date: Tue, 26 Apr 2022 15:16:38 -0400 Subject: [PATCH 2/2] Use strlen instead of mb_strlen strlen is O(1) and mb_strlen is O(n). --- src/Behat/Gherkin/Filter/TagFilter.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Behat/Gherkin/Filter/TagFilter.php b/src/Behat/Gherkin/Filter/TagFilter.php index 5936bc2b..052ef398 100644 --- a/src/Behat/Gherkin/Filter/TagFilter.php +++ b/src/Behat/Gherkin/Filter/TagFilter.php @@ -13,7 +13,6 @@ use Behat\Gherkin\Node\FeatureNode; use Behat\Gherkin\Node\OutlineNode; use Behat\Gherkin\Node\ScenarioInterface; -use function mb_strlen; /** * Filters scenarios by feature/scenario tag. @@ -138,7 +137,7 @@ protected function isTagsMatchCondition($tags) { $satisfies = true; - if (mb_strlen($this->filterString) === 0) { + if (\strlen($this->filterString) === 0) { return $satisfies; }