Skip to content

Commit 686f3c4

Browse files
committed
Split MySQL test files only on LF and CRLF
The query corpus extractor also split lines on a vertical tab, a form feed, and a bare carriage return, and turned them into line feeds. MySQL's comments.test uses each of them on purpose after a version comment, so six distinct queries collapsed into their line feed versions after deduplication. mysqltest ends a line only on LF and CRLF. The regenerated corpus has these six queries back, and they all parse.
1 parent f79b9b3 commit 686f3c4

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

‎packages/mysql-parser/data/mysql-server-query-corpus/mysql-latest.csv‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5765,11 +5765,17 @@ multi line comment */"
57655765
"DO 1 /*!80034 +1*/"
57665766
"DO 1 /*!80034
57675767
+1*/"
5768+
"DO 1 /*!80034 +1*/"
5769+
"DO 1 /*!80034 +1*/"
5770+
"DO 1 /*!80034+1*/"
57685771
"DO 1 /*!80034 +1*/"
57695772
"SELECT 1 + /*!800001+0 */ + 0 AS should_return_2"
57705773
"SELECT 1 /*!080100 +1*/ AS should_return_2"
57715774
"SELECT 1 /*!080100
57725775
+1*/ AS should_return_2"
5776+
"SELECT 1 /*!080100 +1*/ AS should_return_2"
5777+
"SELECT 1 /*!080100 +1*/ AS should_return_2"
5778+
"SELECT 1 /*!080100+1*/ AS should_return_2"
57735779
"SELECT 1 /*!080100 +1*/ AS should_return_2"
57745780
"SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ"
57755781
"CREATE TABLE t1 (s1 INT) ENGINE=InnoDB"
@@ -57565,8 +57571,7 @@ ALTER COLUMN Channel_name DROP DEFAULT"
5756557571
"DROP TABLE IF EXISTS tmp_user"
5756657572
"CREATE TABLE tmp_user AS (SELECT * FROM mysql.user)"
5756757573
"INSERT INTO mysql.user VALUES
57568-
('%','user_sha_pass_wp','','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','','','','',0,0,0,0,'sha256_password','$5$J=M`}N+i=%
57569-
1o6z\'$Ns0lpHRzOCs9T4n5df6ZxAYsUaK1yFMnRGlp3T48AW/','N')"
57574+
('%','user_sha_pass_wp','','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','','','','',0,0,0,0,'sha256_password','$5$J=M`}N+i=% 1o6z\'$Ns0lpHRzOCs9T4n5df6ZxAYsUaK1yFMnRGlp3T48AW/','N')"
5757057575
"UPDATE mysql.user SET Select_priv='Y', Insert_priv='Y', Update_priv='Y', Delete_priv='Y', Create_priv='Y', Drop_priv='Y', Reload_priv='Y', Shutdown_priv='Y', Process_priv='Y', File_priv='Y', Grant_priv='Y', References_priv='Y', Index_priv='Y', Alter_priv='Y', Show_db_priv='Y', Super_priv='Y', Create_tmp_table_priv='Y', Lock_tables_priv='Y', Execute_priv='Y', Repl_slave_priv='Y', Repl_client_priv='Y', Create_view_priv='Y', Show_view_priv='Y', Create_routine_priv='Y', Alter_routine_priv='Y', Create_user_priv='Y', Event_priv='Y', Trigger_priv='Y', Create_tablespace_priv='Y' where user=""user_sha_pass_wp"""
5757157576
"DROP USER 'user_sha_pass_wp'@'%'"
5757257577
"TRUNCATE TABLE mysql.user"

‎packages/mysql-parser/tests/WP_MySQL_Server_Suite_Parser_Tests.php‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class WP_MySQL_Server_Suite_Parser_Tests extends TestCase {
1919
* set is pinned in FAILURES_PATH; update it when the accepted language
2020
* legitimately changes.
2121
*/
22-
const EXPECTED_QUERIES = 69070;
22+
const EXPECTED_QUERIES = 69076;
2323
const EXPECTED_FAILURES = 166;
2424

2525
public function test_corpus_acceptance_rate(): void {
@@ -54,7 +54,7 @@ public function test_corpus_acceptance_rate(): void {
5454
}
5555

5656
/**
57-
* Pin the text of queries from tests that use other character sets, because
57+
* Pin the text of queries that are easy to misread from the test files, because
5858
* the tally can't see a change in the text of a query that still parses.
5959
*
6060
* @dataProvider data_query_texts
@@ -79,6 +79,10 @@ public function data_query_texts(): array {
7979
'UTF-8 bytes that MySQL reads as latin1' => array( 'insert into t1 (id, name) values (1, "óra")' ),
8080
'UTF-8 literal in a koi8r line' => array( "CREATE VIEW v2 AS SELECT _utf8mb3'тест' as c1" ),
8181
'koi8r literal in a UTF-8 line' => array( "CREATE VIEW v2 AS SELECT _koi8r'тест' as c1" ),
82+
'line feed in a version comment' => array( "DO 1 /*!80034\n+1*/" ),
83+
'vertical tab in a version comment' => array( "DO 1 /*!80034\v+1*/" ),
84+
'form feed in a version comment' => array( "DO 1 /*!80034\f+1*/" ),
85+
'carriage return in a version comment' => array( "DO 1 /*!80034\r+1*/" ),
8286
);
8387
}
8488

‎packages/mysql-parser/tools/generate-query-corpus.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,9 @@ function ( $command ) {
229229
// The files are not decoded yet, so the regexes match bytes, not UTF-8.
230230
$contents = preg_replace( '/^\s*(?:if|while)\s*(\((?>(?1)|[^()])*+\))\s*(\{(?>(?2)|[^{}])*+})/im', '', $contents );
231231

232-
foreach ( preg_split( '/\r\n|[\n\x0b\x0c\r]/', $contents ) as $line ) {
232+
// As in mysqltest, only LF and CRLF end a line. Other line separators are part of
233+
// the query, such as the ones that "comments.test" uses to test whitespace.
234+
foreach ( preg_split( '/\r?\n/', $contents ) as $line ) {
233235
$lines += 1;
234236

235237
// Skip command bodies for perl, append_file, and write_file commands.

0 commit comments

Comments
 (0)