Skip to content

Commit 20f82be

Browse files
committed
Improve invalid UTF-8 test cases and their docs
1 parent 5196a05 commit 20f82be

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

tests/WP_SQLite_Driver_Tests.php

+27-4
Original file line numberDiff line numberDiff line change
@@ -4972,10 +4972,33 @@ function ( string $utf8_literal ) {
49724972
$this->assertSame( "'👪'", $quote( '👪' ) );
49734973
$this->assertSame( "'Ʈềʂᴛӏń𝒈 𝙨𝑜ɱê Ū𝐓Ϝ-8 𝒄𝒽ȃᵲ𝛼çṱ𝘦ᴦ𐑈.'", $quote( 'Ʈềʂᴛӏń𝒈 𝙨𝑜ɱê Ū𝐓Ϝ-8 𝒄𝒽ȃᵲ𝛼çṱ𝘦ᴦ𐑈.' ) );
49744974

4975-
// Invalid UTF-8 sequences may fail to be preserved.
4976-
// The following 2-byte sequence with a single quote as the last byte
4977-
// is not a valid UTF-8 sequence. The single quote gets escaped.
4978-
// At the moment, this is the intended behavior.
4975+
// Invalid UTF-8: An incomplete 2-byte sequence is left unchanged.
4976+
$this->assertSame(
4977+
"'" . chr( 0xC0 ) . "'",
4978+
$quote( chr( 0xC0 ) )
4979+
);
4980+
4981+
// Invalid UTF-8: A surrogate pair is left unchanged.
4982+
$this->assertSame(
4983+
"'" . chr( 0xED ) . chr( 0xA0 ) . chr( 0x80 ) . "'",
4984+
$quote( chr( 0xED ) . chr( 0xA0 ) . chr( 0x80 ) )
4985+
);
4986+
4987+
// Invalid UTF-8: Overlong encoding of ASCII NULL is left unchanged.
4988+
$this->assertSame(
4989+
"'" . chr( 0xE0 ) . chr( 0x80 ) . chr( 0x80 ) . "'",
4990+
$quote( chr( 0xE0 ) . chr( 0x80 ) . chr( 0x80 ) )
4991+
);
4992+
4993+
// Invalid UTF-8: A 2-byte sequence prefix, followed by an ASCII NULL.
4994+
// The NULL is escaped, leaving the C0 prefix an incomplete sequence.
4995+
$this->assertSame(
4996+
"'" . chr( 0xC0 ) . "{$backslash}0" . "'",
4997+
$quote( chr( 0xC0 ) . chr( 0 ) )
4998+
);
4999+
5000+
// Invalid UTF-8: A 2-byte sequence prefix, followed by a single quote.
5001+
// The single quote is escaped, leaving the C0 prefix an incomplete sequence.
49795002
$this->assertSame(
49805003
"'" . chr( 0xC0 ) . chr( 39 ) . chr( 39 ) . "'",
49815004
$quote( chr( 0xC0 ) . chr( 39 ) )

0 commit comments

Comments
 (0)