From cfb447326b39b71b8109c846da85ba61e46408e7 Mon Sep 17 00:00:00 2001 From: Jerry Martinez Date: Tue, 3 Dec 2019 12:03:56 -0500 Subject: [PATCH] Reorder ByteSequence constants from longest to shortest. Fix #363. --- src/ByteSequence.php | 20 ++++++++++---------- tests/ByteSequenceTest.php | 4 ++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/ByteSequence.php b/src/ByteSequence.php index deb01863..4dabf24f 100644 --- a/src/ByteSequence.php +++ b/src/ByteSequence.php @@ -17,27 +17,27 @@ interface ByteSequence { /** - * UTF-8 BOM sequence. + * UTF-32 BE BOM sequence. */ - const BOM_UTF8 = "\xEF\xBB\xBF"; + const BOM_UTF32_BE = "\x00\x00\xFE\xFF"; /** - * UTF-16 BE BOM sequence. + * UTF-32 LE BOM sequence. */ - const BOM_UTF16_BE = "\xFE\xFF"; + const BOM_UTF32_LE = "\xFF\xFE\x00\x00"; /** - * UTF-16 LE BOM sequence. + * UTF-8 BOM sequence. */ - const BOM_UTF16_LE = "\xFF\xFE"; + const BOM_UTF8 = "\xEF\xBB\xBF"; /** - * UTF-32 BE BOM sequence. + * UTF-16 BE BOM sequence. */ - const BOM_UTF32_BE = "\x00\x00\xFE\xFF"; + const BOM_UTF16_BE = "\xFE\xFF"; /** - * UTF-32 LE BOM sequence. + * UTF-16 LE BOM sequence. */ - const BOM_UTF32_LE = "\xFF\xFE\x00\x00"; + const BOM_UTF16_LE = "\xFF\xFE"; } diff --git a/tests/ByteSequenceTest.php b/tests/ByteSequenceTest.php index 31465e08..4b9365f6 100644 --- a/tests/ByteSequenceTest.php +++ b/tests/ByteSequenceTest.php @@ -55,6 +55,10 @@ public function ByteSequenceMatchProvider(): array 'sequence' => 'The quick brown fox '.ByteSequence::BOM_UTF8.' jumps over the lazy dog', 'expected' => '', ], + 'UTF-32 LE BOM sequence' => [ + 'sequence' => chr(255).chr(254).chr(0).chr(0), + 'expected' => ByteSequence::BOM_UTF32_LE, + ], ]; } }