Report correct position for SQL files with unicode characters
authorChristian Weiske <cweiske@cweiske.de>
Tue, 14 Apr 2020 19:07:43 +0000 (21:07 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Tue, 14 Apr 2020 19:07:43 +0000 (21:07 +0200)
Resolves: https://github.com/cweiske/php-sqllint/issues/14

src/phpsqllint/Cli.php
tests/files/unicode-error.sql [new file with mode: 0644]

index 1501815..61acfa0 100644 (file)
@@ -91,7 +91,7 @@ class Cli
         $lines = array(1 => 0);
         $pos = -1;
         $line = 1;
-        while (false !== $pos = strpos($sql, "\n", ++$pos)) {
+        while (false !== $pos = mb_strpos($sql, "\n", ++$pos)) {
             $lines[++$line] = $pos;
         }
 
diff --git a/tests/files/unicode-error.sql b/tests/files/unicode-error.sql
new file mode 100644 (file)
index 0000000..8404cd6
--- /dev/null
@@ -0,0 +1,2 @@
+SELECT 'รครถ'
+SELECT 1