Skip to content

Commit de705d5

Browse files
Fix split filter for php >=8.0 in case of empty separator (#213)
Co-authored-by: pavlikovsky <[email protected]>
1 parent 1f4477c commit de705d5

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Liquid/StandardFilters.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,10 @@ public static function split($input, $pattern)
621621
return [];
622622
}
623623

624+
if ($pattern === '') {
625+
return mb_str_split($input);
626+
}
627+
624628
return explode($pattern, $input);
625629
}
626630

tests/Liquid/StandardFiltersTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,21 @@ public function testSplit()
881881
array('123', '123', '123'),
882882
'0'
883883
),
884+
array(
885+
'phrase',
886+
array('p', 'h', 'r', 'a', 's', 'e'),
887+
''
888+
),
889+
array(
890+
'phrase',
891+
array('phrase'),
892+
null
893+
),
894+
array(
895+
'123 123 123',
896+
array('123', '123', '123'),
897+
' '
898+
),
884899
);
885900

886901
foreach ($data as $item) {

0 commit comments

Comments
 (0)