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 3 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
8 changes: 8 additions & 0 deletions src/Liquid/StandardFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,14 @@ 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 👍

}

if (empty($pattern)) {
Copy link
Collaborator

@sanmai sanmai Mar 19, 2024

Choose a reason for hiding this comment

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

There's a problem in this condition. Can you see it?

return [$input];
}

return explode($pattern, $input);
}

Expand Down
10 changes: 10 additions & 0 deletions tests/Liquid/StandardFiltersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,16 @@ 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
)
);

foreach ($data as $item) {
Expand Down
Loading