File tree Expand file tree Collapse file tree 3 files changed +37
-1
lines changed
Expand file tree Collapse file tree 3 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 33## [ Unreleased]
44
55* Fixed parsing SQL comment at the end of query.
6+ * Improved handing of non utf-8 strings.
67
78## [ 4.1.7] - 2017-06-06
89
Original file line number Diff line number Diff line change @@ -75,7 +75,11 @@ public function __construct($str)
7575 $ this ->byteIdx = 0 ;
7676 $ this ->charIdx = 0 ;
7777 $ this ->byteLen = mb_strlen ($ str , '8bit ' );
78- $ this ->charLen = mb_strlen ($ str , 'UTF-8 ' );
78+ if (! mb_check_encoding ($ str , 'UTF-8 ' )) {
79+ $ this ->charLen = 0 ;
80+ } else {
81+ $ this ->charLen = mb_strlen ($ str , 'UTF-8 ' );
82+ }
7983 }
8084
8185 /**
Original file line number Diff line number Diff line change @@ -82,4 +82,35 @@ public function testToString()
8282 $ str = new UtfString (static ::TEST_PHRASE );
8383 $ this ->assertEquals (static ::TEST_PHRASE , (string ) $ str );
8484 }
85+
86+ /**
87+ * Test access to string
88+ *
89+ * @dataProvider utf8_strings
90+ */
91+ public function testAccess ($ text , $ pos10 , $ pos20 )
92+ {
93+ $ str = new UtfString ($ text );
94+ $ this ->assertEquals ($ pos10 , $ str ->offsetGet (10 ));
95+ $ this ->assertEquals ($ pos20 , $ str ->offsetGet (20 ));
96+ $ this ->assertEquals ($ pos10 , $ str ->offsetGet (10 ));
97+ }
98+
99+ public function utf8_strings ()
100+ {
101+ return array (
102+ 'ascii ' => array (
103+ 'abcdefghijklmnopqrstuvwxyz ' , 'k ' , 'u '
104+ ),
105+ 'unicode ' => array (
106+ 'áéíóúýěřťǔǐǒǎšďȟǰǩľžčǚň ' , 'ǐ ' , 'č '
107+ ),
108+ 'emoji ' => array (
109+ '😂😄😃😀😊😉😍😘😚😗😂👿😮😨😱😠😡😤😖😆😋👯 ' , '😂 ' , '😋 '
110+ ),
111+ 'iso ' => array (
112+ "P \xf8\xed\xb9ern \xec \xbelu \xbbou \xe8k \xfd k \xf3d \xfap \xecl \xef\xe1belsk \xe9 k \xf3dy " , null , null
113+ ),
114+ );
115+ }
85116}
You can’t perform that action at this time.
0 commit comments