From 759e20e6d332d8a79d2608db9ebcb30a325cd019 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 14 Jan 2020 18:54:59 +0100 Subject: [PATCH] [String] add missing encoding when calling mb_ord() --- .../Component/String/AbstractUnicodeString.php | 12 +++++++++++- src/Symfony/Component/String/CodePointString.php | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/String/AbstractUnicodeString.php b/src/Symfony/Component/String/AbstractUnicodeString.php index 19ad5e8939..bc3e05cd6f 100644 --- a/src/Symfony/Component/String/AbstractUnicodeString.php +++ b/src/Symfony/Component/String/AbstractUnicodeString.php @@ -172,7 +172,17 @@ abstract class AbstractUnicodeString extends AbstractString { $str = $this->slice($offset, 1); - return '' === $str->string ? [] : array_map('mb_ord', preg_split('//u', $str->string, -1, PREG_SPLIT_NO_EMPTY)); + if ('' === $str->string) { + return []; + } + + $codePoints = []; + + foreach (preg_split('//u', $str->string, -1, PREG_SPLIT_NO_EMPTY) as $c) { + $codePoints[] = mb_ord($c, 'UTF-8'); + } + + return $codePoints; } public function folded(bool $compat = true): parent diff --git a/src/Symfony/Component/String/CodePointString.php b/src/Symfony/Component/String/CodePointString.php index 8a729bb9e1..d1ac915701 100644 --- a/src/Symfony/Component/String/CodePointString.php +++ b/src/Symfony/Component/String/CodePointString.php @@ -79,7 +79,7 @@ class CodePointString extends AbstractUnicodeString { $str = $offset ? $this->slice($offset, 1) : $this; - return '' === $str->string ? [] : [mb_ord($str->string)]; + return '' === $str->string ? [] : [mb_ord($str->string, 'UTF-8')]; } public function endsWith($suffix): bool