diff options
author | Michal Čihař <michal@cihar.com> | 2017-06-15 15:20:10 +0200 |
---|---|---|
committer | Michal Čihař <michal@cihar.com> | 2017-06-15 15:21:30 +0200 |
commit | e89c52b8d6734739a7fdc2c0ee06645ef9c5b697 (patch) | |
tree | 4886198d2673c4190943ee9ac8f730edcde2da10 /tests | |
parent | 7cad6fa657e8dd70704b4163bb09751d98408f9b (diff) | |
download | sql-parser-e89c52b8d6734739a7fdc2c0ee06645ef9c5b697.zip sql-parser-e89c52b8d6734739a7fdc2c0ee06645ef9c5b697.tar.gz sql-parser-e89c52b8d6734739a7fdc2c0ee06645ef9c5b697.tar.bz2 |
Improve UtfString handling of invalid strings
First check whether string is actually utf-8 before trying to process it
as it.
Fixes https://github.com/phpmyadmin/phpmyadmin/issues/13385
Signed-off-by: Michal Čihař <michal@cihar.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Misc/UtfStringTest.php | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/Misc/UtfStringTest.php b/tests/Misc/UtfStringTest.php index d7c4404..1e5222c 100644 --- a/tests/Misc/UtfStringTest.php +++ b/tests/Misc/UtfStringTest.php @@ -82,4 +82,35 @@ class UtfStringTest extends TestCase $str = new UtfString(static::TEST_PHRASE); $this->assertEquals(static::TEST_PHRASE, (string) $str); } + + /** + * Test access to string + * + * @dataProvider utf8_strings + */ + public function testAccess($text, $pos10, $pos20) + { + $str = new UtfString($text); + $this->assertEquals($pos10, $str->offsetGet(10)); + $this->assertEquals($pos20, $str->offsetGet(20)); + $this->assertEquals($pos10, $str->offsetGet(10)); + } + + public function utf8_strings() + { + return array( + 'ascii' => array( + 'abcdefghijklmnopqrstuvwxyz', 'k', 'u' + ), + 'unicode' => array( + 'áéíóúýěřťǔǐǒǎšďȟǰǩľžčǚň', 'ǐ', 'č' + ), + 'emoji' => array( + '😂😄😃😀😊😉😍😘😚😗😂👿😮😨😱😠😡😤😖😆😋👯', '😂', '😋' + ), + 'iso' => array( + "P\xf8\xed\xb9ern\xec \xbelu\xbbou\xe8k\xfd k\xf3d \xfap\xecl \xef\xe1belsk\xe9 k\xf3dy", null, null + ), + ); + } } |