Skip to content

Commit

Permalink
Merge pull request #365 from thephpleague/bugfix/bom_match
Browse files Browse the repository at this point in the history
#363 resolve bom_match detection bug
  • Loading branch information
nyamsprod committed Dec 13, 2019
2 parents b546ec0 + 963963a commit 5759030
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use function count;
use function is_array;
use function iterator_to_array;
use function rsort;
use function strpos;
use const COUNT_RECURSIVE;

Expand All @@ -33,8 +34,11 @@
function bom_match(string $str): string
{
static $list;
if (null === $list) {
$list = (new ReflectionClass(ByteSequence::class))->getConstants();

$list = $list ?? (new ReflectionClass(ByteSequence::class))->getConstants();
rsort($list);
}

foreach ($list as $sequence) {
if (0 === strpos($str, $sequence)) {
Expand Down
4 changes: 4 additions & 0 deletions tests/ByteSequenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ public function ByteSequenceMatchProvider(): array
'sequence' => 'The quick brown fox '.ByteSequence::BOM_UTF8.' jumps over the lazy dog',
'expected' => '',
],
'UTF32 LE BOM sequence' => [
'sequence' => chr(255).chr(254).chr(0).chr(0),
'expected' => ByteSequence::BOM_UTF32_LE,
],
];
}
}

0 comments on commit 5759030

Please sign in to comment.