Skip to content

Commit

Permalink
Fix split filter for php >=8.0 in case of empty separator (#213)
Browse files Browse the repository at this point in the history
Co-authored-by: pavlikovsky <[email protected]>
  • Loading branch information
oleksii-pavlikovskii-eleks-com and CipHuK authored Mar 19, 2024
1 parent 1f4477c commit de705d5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Liquid/StandardFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,10 @@ public static function split($input, $pattern)
return [];
}

if ($pattern === '') {
return mb_str_split($input);
}

return explode($pattern, $input);
}

Expand Down
15 changes: 15 additions & 0 deletions tests/Liquid/StandardFiltersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit de705d5

Please sign in to comment.