Skip to content

Commit 263ae9d

Browse files
committed
Make Assert\Assertion::stringify() UTF-8 safe.
1 parent 448bc4f commit 263ae9d

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/Assert/Assertion.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2768,8 +2768,8 @@ protected static function stringify($value): string
27682768
} elseif (\is_scalar($value)) {
27692769
$val = (string)$value;
27702770

2771-
if (\strlen($val) > 100) {
2772-
$val = \substr($val, 0, 97).'...';
2771+
if (\mb_strlen($val) > 100) {
2772+
$val = \mb_substr($val, 0, 97).'...';
27732773
}
27742774

27752775
$result = $val;

tests/Assert/Tests/AssertTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2103,6 +2103,18 @@ public function testStringifyTruncatesStringValuesLongerThan100CharactersAppropr
21032103
$this->assertTrue(Assertion::float($string));
21042104
}
21052105

2106+
/**
2107+
* @expectedException \Assert\AssertionFailedException
2108+
* @expectedExceptionCode \Assert\Assertion::INVALID_FLOAT
2109+
* @expectedExceptionMessage ငါကနံပါတ်မဟုတ်ဘူးငါကနံပါတ်မဟုတ်ဘူးငါကနံပါတ်မဟုတ်ဘူးငါကနံပါတ်မဟုတ်ဘူးငါကနံပါတ်မဟုတ်ဘူးငါကနံပါတ်မဟု...
2110+
*/
2111+
public function testStringifyTruncatesStringValuesLongerThan100CharactersAppropriatelyAndIsMultibyteValid()
2112+
{
2113+
$string = str_repeat('ငါကနံပါတ်မဟုတ်ဘူး', 11);
2114+
2115+
$this->assertTrue(Assertion::float($string));
2116+
}
2117+
21062118
/**
21072119
* @expectedException \Assert\AssertionFailedException
21082120
* @expectedExceptionCode \Assert\Assertion::INVALID_FLOAT

0 commit comments

Comments
 (0)