From de705d5629f037ce078ae068fd98c6cd2ef6ba51 Mon Sep 17 00:00:00 2001 From: oleksii-pavlikovskii-eleks-com <118443397+oleksii-pavlikovskii-eleks-com@users.noreply.github.com> Date: Tue, 19 Mar 2024 12:22:06 +0200 Subject: [PATCH] Fix split filter for php >=8.0 in case of empty separator (#213) Co-authored-by: pavlikovsky --- src/Liquid/StandardFilters.php | 4 ++++ tests/Liquid/StandardFiltersTest.php | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/Liquid/StandardFilters.php b/src/Liquid/StandardFilters.php index 433bd41..76a9f7d 100644 --- a/src/Liquid/StandardFilters.php +++ b/src/Liquid/StandardFilters.php @@ -621,6 +621,10 @@ public static function split($input, $pattern) return []; } + if ($pattern === '') { + return mb_str_split($input); + } + return explode($pattern, $input); } diff --git a/tests/Liquid/StandardFiltersTest.php b/tests/Liquid/StandardFiltersTest.php index b8efb7a..8bafd46 100644 --- a/tests/Liquid/StandardFiltersTest.php +++ b/tests/Liquid/StandardFiltersTest.php @@ -881,6 +881,21 @@ public function testSplit() array('123', '123', '123'), '0' ), + array( + 'phrase', + array('p', 'h', 'r', 'a', 's', 'e'), + '' + ), + array( + 'phrase', + array('phrase'), + null + ), + array( + '123 123 123', + array('123', '123', '123'), + ' ' + ), ); foreach ($data as $item) {