Skip to content

Commit

Permalink
bug #38546 [String] fix "is too large" ValueError on PHP 8 (nicolas-g…
Browse files Browse the repository at this point in the history
…rekas)

This PR was merged into the 5.1 branch.

Discussion
----------

[String] fix "is too large" ValueError on PHP 8

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

Commits
-------

15c22c69e4 [String] fix "is too large" ValueError on PHP 8
  • Loading branch information
nicolas-grekas committed Oct 13, 2020
2 parents 81ea5de + 09297ff commit 615bde9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions UnicodeString.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public function slice(int $start = 0, int $length = null): AbstractString
{
$str = clone $this;
try {
$str->string = (string) grapheme_substr($this->string, $start, $length ?? \PHP_INT_MAX);
$str->string = (string) grapheme_substr($this->string, $start, $length ?? 2147483647);
} catch (\ValueError $e) {
$str->string = '';
}
Expand All @@ -280,8 +280,8 @@ public function splice(string $replacement, int $start = 0, int $length = null):
{
$str = clone $this;
$start = $start ? \strlen(grapheme_substr($this->string, 0, $start)) : 0;
$length = $length ? \strlen(grapheme_substr($this->string, $start, $length ?? \PHP_INT_MAX)) : $length;
$str->string = substr_replace($this->string, $replacement, $start, $length ?? \PHP_INT_MAX);
$length = $length ? \strlen(grapheme_substr($this->string, $start, $length ?? 2147483647)) : $length;
$str->string = substr_replace($this->string, $replacement, $start, $length ?? 2147483647);
normalizer_is_normalized($str->string) ?: $str->string = normalizer_normalize($str->string);

if (false === $str->string) {
Expand All @@ -293,7 +293,7 @@ public function splice(string $replacement, int $start = 0, int $length = null):

public function split(string $delimiter, int $limit = null, int $flags = null): array
{
if (1 > $limit = $limit ?? \PHP_INT_MAX) {
if (1 > $limit = $limit ?? 2147483647) {
throw new InvalidArgumentException('Split limit must be a positive integer.');
}

Expand Down

0 comments on commit 615bde9

Please sign in to comment.