From 17efd25f49c4adb71ff48890fba0b28559d71662 Mon Sep 17 00:00:00 2001 From: pavlikovsky Date: Mon, 18 Mar 2024 18:05:58 +0200 Subject: [PATCH 1/4] Fix split filter for php >=8.0 --- src/Liquid/StandardFilters.php | 8 ++++++++ tests/Liquid/StandardFiltersTest.php | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Liquid/StandardFilters.php b/src/Liquid/StandardFilters.php index 433bd41..4c116d0 100644 --- a/src/Liquid/StandardFilters.php +++ b/src/Liquid/StandardFilters.php @@ -621,6 +621,14 @@ public static function split($input, $pattern) return []; } + if ($pattern === '') { + return mb_str_split($input); + } + + if (empty($pattern)) { + return [$input]; + } + return explode($pattern, $input); } diff --git a/tests/Liquid/StandardFiltersTest.php b/tests/Liquid/StandardFiltersTest.php index 729266b..99de958 100644 --- a/tests/Liquid/StandardFiltersTest.php +++ b/tests/Liquid/StandardFiltersTest.php @@ -867,19 +867,32 @@ public function testSplit() array( '', array(), + '-' ), array( null, array(), + '-' ), array( 'two-one-three', array('two', 'one', 'three'), + '-' ), + array( + 'phrase', + array('p', 'h', 'r', 'a', 's', 'e'), + '' + ), + array( + 'phrase', + array('phrase'), + null + ) ); foreach ($data as $item) { - $this->assertEquals($item[1], StandardFilters::split($item[0], '-')); + $this->assertEquals($item[1], StandardFilters::split($item[0], $item[2])); } } From 55e5d22c622ce661f693bbd16ba23f0886224a5a Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Tue, 19 Mar 2024 15:44:38 +0900 Subject: [PATCH 2/4] Apply suggestions from code review --- tests/Liquid/StandardFiltersTest.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/Liquid/StandardFiltersTest.php b/tests/Liquid/StandardFiltersTest.php index 6cf6f9c..141b2db 100644 --- a/tests/Liquid/StandardFiltersTest.php +++ b/tests/Liquid/StandardFiltersTest.php @@ -867,17 +867,14 @@ public function testSplit() array( '', array(), - '-' ), array( null, array(), - '-' ), array( 'two-one-three', array('two', 'one', 'three'), - '-' ), array( '12301230123', @@ -885,7 +882,7 @@ public function testSplit() '0' ), array( - 'phrase', + 'phrase', array('p', 'h', 'r', 'a', 's', 'e'), '' ), From 378c813d33f7ee203e1a6c2167d9e1a6f023a3c4 Mon Sep 17 00:00:00 2001 From: pavlikovsky Date: Tue, 19 Mar 2024 12:11:36 +0200 Subject: [PATCH 3/4] Fix split filter after code review --- src/Liquid/StandardFilters.php | 4 ---- tests/Liquid/StandardFiltersTest.php | 12 +++++++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Liquid/StandardFilters.php b/src/Liquid/StandardFilters.php index 4c116d0..76a9f7d 100644 --- a/src/Liquid/StandardFilters.php +++ b/src/Liquid/StandardFilters.php @@ -625,10 +625,6 @@ public static function split($input, $pattern) return mb_str_split($input); } - if (empty($pattern)) { - return [$input]; - } - return explode($pattern, $input); } diff --git a/tests/Liquid/StandardFiltersTest.php b/tests/Liquid/StandardFiltersTest.php index 141b2db..ae326a1 100644 --- a/tests/Liquid/StandardFiltersTest.php +++ b/tests/Liquid/StandardFiltersTest.php @@ -890,7 +890,17 @@ public function testSplit() 'phrase', array('phrase'), null - ) + ), + array( + '12301230123', + array('123', '123', '123'), + '0' + ), + array( + '123 123 123', + array('123', '123', '123'), + ' ' + ), ); foreach ($data as $item) { From d5bb665e3f1c147d7d25e4002cf091e048cc263f Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Tue, 19 Mar 2024 19:18:51 +0900 Subject: [PATCH 4/4] Update tests/Liquid/StandardFiltersTest.php --- tests/Liquid/StandardFiltersTest.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/Liquid/StandardFiltersTest.php b/tests/Liquid/StandardFiltersTest.php index ae326a1..8bafd46 100644 --- a/tests/Liquid/StandardFiltersTest.php +++ b/tests/Liquid/StandardFiltersTest.php @@ -891,11 +891,6 @@ public function testSplit() array('phrase'), null ), - array( - '12301230123', - array('123', '123', '123'), - '0' - ), array( '123 123 123', array('123', '123', '123'),