From 9993f3d3f6ed0f899ff0ae044a3860b2828cc18f Mon Sep 17 00:00:00 2001 From: Matias Melograno Date: Mon, 23 May 2022 17:11:37 -0300 Subject: [PATCH 1/3] moved strlen function after checking if parameter is string --- CHANGES.txt | 3 +++ .../Cache/Storage/Adapter/PRedis.php | 2 +- .../Condition/Matcher/ContainsString.php | 3 +-- .../Grammar/Condition/Matcher/EndsWith.php | 6 ++--- src/SplitIO/Version.php | 2 +- tests/Suite/Adapter/RedisAdapterTest.php | 26 +++++++++++++++++++ tests/Suite/Matchers/MatchersTest.php | 2 ++ 7 files changed, 36 insertions(+), 8 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 83b91d3a..97857ca7 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,6 @@ +7.1.2 (May 24, 2022) + - Added validation when strlen is not receiving string to avoid Fatal Error in PHP 8. + 7.1.1 (March 28, 2022) - Removed unused logic for HTTP and requests dependency. - Removed all producer logic for Storages. diff --git a/src/SplitIO/Component/Cache/Storage/Adapter/PRedis.php b/src/SplitIO/Component/Cache/Storage/Adapter/PRedis.php index 9e941c3e..d4758a47 100644 --- a/src/SplitIO/Component/Cache/Storage/Adapter/PRedis.php +++ b/src/SplitIO/Component/Cache/Storage/Adapter/PRedis.php @@ -279,7 +279,7 @@ public function getKeys($pattern = '*') private static function normalizePrefix($prefix) { - if ($prefix && strlen($prefix)) { + if ($prefix && is_string($prefix) && strlen($prefix)) { if ($prefix[strlen($prefix) - 1] == '.') { return $prefix; } else { diff --git a/src/SplitIO/Grammar/Condition/Matcher/ContainsString.php b/src/SplitIO/Grammar/Condition/Matcher/ContainsString.php index 5eb5690f..581856d9 100644 --- a/src/SplitIO/Grammar/Condition/Matcher/ContainsString.php +++ b/src/SplitIO/Grammar/Condition/Matcher/ContainsString.php @@ -17,8 +17,7 @@ public function __construct($data, $negate = false, $attribute = null) protected function evalKey($key) { - $keyLength = strlen($key); - if (!is_array($this->containsStringMatcherData) || !is_string($key) || $keyLength == 0) { + if (!is_array($this->containsStringMatcherData) || !is_string($key) || strlen($key) == 0) { return false; } diff --git a/src/SplitIO/Grammar/Condition/Matcher/EndsWith.php b/src/SplitIO/Grammar/Condition/Matcher/EndsWith.php index eb3b6db6..97f0f458 100644 --- a/src/SplitIO/Grammar/Condition/Matcher/EndsWith.php +++ b/src/SplitIO/Grammar/Condition/Matcher/EndsWith.php @@ -17,14 +17,12 @@ public function __construct($data, $negate = false, $attribute = null) protected function evalKey($key) { - $keyLength = strlen($key); - if (!is_array($this->endsWithMatcherData) || !is_string($key) || $keyLength == 0) { + if (!is_array($this->endsWithMatcherData) || !is_string($key) || strlen($key) == 0) { return false; } foreach ($this->endsWithMatcherData as $item) { - $itemLength = strlen($item); - if (is_string($item) && substr($key, -$itemLength) == $item) { + if (is_string($item) && substr($key, -strlen($item)) == $item) { return true; } } diff --git a/src/SplitIO/Version.php b/src/SplitIO/Version.php index c51d3d28..d6d780fe 100644 --- a/src/SplitIO/Version.php +++ b/src/SplitIO/Version.php @@ -3,5 +3,5 @@ class Version { - const CURRENT = '7.1.1'; + const CURRENT = '7.1.2-rc1'; } diff --git a/tests/Suite/Adapter/RedisAdapterTest.php b/tests/Suite/Adapter/RedisAdapterTest.php index 4b14d2be..dac74c26 100644 --- a/tests/Suite/Adapter/RedisAdapterTest.php +++ b/tests/Suite/Adapter/RedisAdapterTest.php @@ -514,4 +514,30 @@ public function testRedisSSLWithSentinelFails() ), )); } + + public function testRedisWithWrongPrefix() + { + $predis = new PRedis(array( + 'parameters' => array( + 'scheme' => 'tcp', + 'host' => 'localhost', + 'port' => 6379, + 'timeout' => 881, + 'database' => 0 + ), + 'options' => array( + 'prefix' => array() + ) + )); + $predisClient = new \Predis\Client([ + 'host' => REDIS_HOST, + 'port' => REDIS_PORT, + ]); + $predisClient->set('{SPLITIO}.this_is_a_test_key', 'this-is-a-test-value'); + + $value = $predis->get('{SPLITIO}.this_is_a_test_key'); + $this->assertEquals('this-is-a-test-value', $value); + + $predisClient->del('{SPLITIO}.this_is_a_test_key'); + } } diff --git a/tests/Suite/Matchers/MatchersTest.php b/tests/Suite/Matchers/MatchersTest.php index 6b85b0dc..f0a1c57a 100644 --- a/tests/Suite/Matchers/MatchersTest.php +++ b/tests/Suite/Matchers/MatchersTest.php @@ -94,6 +94,7 @@ public function testEndsWithMatcher() $this->assertEquals($matcher->evaluate('testJKL'), false); $this->assertEquals($matcher->evaluate(''), false); $this->assertEquals($matcher->evaluate(null), false); + $this->assertEquals($matcher->evaluate(array("some")), false); } public function testContainsStringMatcher() @@ -118,6 +119,7 @@ public function testContainsStringMatcher() $this->assertEquals($matcher->evaluate('Curabitur'), false); $this->assertEquals($matcher->evaluate(''), false); $this->assertEquals($matcher->evaluate(null), false); + $this->assertEquals($matcher->evaluate(array("some")), false); } From 7d5a2e9850bc351432627447bb576cb1f2a0ce06 Mon Sep 17 00:00:00 2001 From: Matias Melograno Date: Tue, 24 May 2022 15:44:49 -0300 Subject: [PATCH 2/3] preparation of release 7.1.2 --- CHANGES.txt | 2 +- src/SplitIO/Version.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 97857ca7..e0a866ab 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,5 +1,5 @@ 7.1.2 (May 24, 2022) - - Added validation when strlen is not receiving string to avoid Fatal Error in PHP 8. + - Added validation when `strlen` is not receiving string to avoid Fatal Error in PHP 8. 7.1.1 (March 28, 2022) - Removed unused logic for HTTP and requests dependency. diff --git a/src/SplitIO/Version.php b/src/SplitIO/Version.php index d6d780fe..6c1aacc4 100644 --- a/src/SplitIO/Version.php +++ b/src/SplitIO/Version.php @@ -3,5 +3,5 @@ class Version { - const CURRENT = '7.1.2-rc1'; + const CURRENT = '7.1.2'; } From 4e47adebe3cd0b64ec5932c434354e9104fbf2b7 Mon Sep 17 00:00:00 2001 From: Matias Melograno Date: Tue, 24 May 2022 15:47:24 -0300 Subject: [PATCH 3/3] updated changelog --- CHANGES.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index e0a866ab..ddcd9237 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,5 +1,5 @@ 7.1.2 (May 24, 2022) - - Added validation when `strlen` is not receiving string to avoid Fatal Error in PHP 8. + - Updated validations to comply with PHP8's stricter type validations. 7.1.1 (March 28, 2022) - Removed unused logic for HTTP and requests dependency.