Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix split filter for php >=8.0 in case of empty separator #213

Merged
merged 5 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Matches the behavior of the upstream project 👍

}

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(
sanmai marked this conversation as resolved.
Show resolved Hide resolved
'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
Loading