diff --git a/CHANGELOG b/CHANGELOG index ecc59c5a4..ef8f11937 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ # 3.30.0 (2026-XX-XX) + * Fix `split`, `random`, and `shuffle` merging a trailing newline into the last character of a string + * Speed up splitting a string into characters in `split`, `random`, and `shuffle` * Speed up adding extensions to an environment * Fix the escaping safe analysis retaining every compiled template node for the lifetime of the environment * Speed up loading a template that the environment has already loaded diff --git a/src/Extension/CoreExtension.php b/src/Extension/CoreExtension.php index d62f733b2..f5f5e3952 100644 --- a/src/Extension/CoreExtension.php +++ b/src/Extension/CoreExtension.php @@ -1263,19 +1263,19 @@ final class CoreExtension extends AbstractExtension } /** - * Unicode version of str_split(): splits at every position except after the start and before the end. + * Unicode version of str_split(), an empty string giving a single empty character. * - * @return list + * @return non-empty-list * * @throws RuntimeError When the string cannot be split into characters */ private static function splitIntoCharacters(string $string, string $name): array { - if (false === $characters = preg_split('/(? "ab\n"] +--EXPECT-- +"\nba" +["a","b","\n"] +3 +1