bug #35339 [String] add missing encoding when calling mb_ord() (nicolas-grekas)

This PR was merged into the 5.0 branch.

Discussion
----------

[String] add missing encoding when calling mb_ord()

| Q             | A
| ------------- | ---
| Branch?       | 5.0
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Commits
-------

759e20e6d3 [String] add missing encoding when calling mb_ord()
This commit is contained in:
Nicolas Grekas 2020-01-20 13:22:08 +01:00
commit 0dcf2fcdf5
2 changed files with 12 additions and 2 deletions

View File

@ -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

View File

@ -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