From d640a5c84385794642fb96675cdf206955bfb1c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Fri, 23 Oct 2020 21:07:40 +0200 Subject: [PATCH 1/3] Space removal before closing bracket only takes place in case of leading '.' --- lib/c_tokenizer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/c_tokenizer.c b/lib/c_tokenizer.c index 55ff8172a..4f6085907 100644 --- a/lib/c_tokenizer.c +++ b/lib/c_tokenizer.c @@ -354,7 +354,7 @@ char *mysql_query_digest_and_first_comment(char *s, int _len, char **first_comme continue; } // supress spaces before closing brakets - if (p >= r && (*s == ')')) { + if (p >= r && *p == '.' && is_space_char(prev_char) && (*s == ')')) { prev_char = *s; --p_r; *p_r++ = *s; From 4281d4cc3c9ff014c74e79c2d0338732b7d1c078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Fri, 23 Oct 2020 21:09:04 +0200 Subject: [PATCH 2/3] Added more cases to tokenizer test to test new space removal behavior --- test/tap/tests/test_tokenizer-t.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/test/tap/tests/test_tokenizer-t.cpp b/test/tap/tests/test_tokenizer-t.cpp index 39b3bc40f..d528d3cfa 100644 --- a/test/tap/tests/test_tokenizer-t.cpp +++ b/test/tap/tests/test_tokenizer-t.cpp @@ -51,7 +51,15 @@ const std::vector queries { "SELECT * FROM tablename WHERE id IN (1,2,3,4,5,6,7,8,9,10)", "SELECT * FROM tablename WHERE id IN (1,2,3,4)", // invalid request grouping - "SELECT * tablename where id IN (1,2,3,4,5,6,7,8, AND j in (1,2,3,4,5,6 and k=1" + "SELECT * tablename where id IN (1,2,3,4,5,6,7,8, AND j in (1,2,3,4,5,6 and k=1", + // random insert queries + "INSERT INTO db.table(col1) VALUES ('val')", + "INSERT INTO db.table (col1) VALUES ('val')", + "INSERT INTO db.table( col1) VALUES ( 'val' )", + "INSERT INTO db.table( col1) VALUES ( 'val' )", + "INSERT INTO db.table ( col1 ) VALUES ( 'val' )", + "INSERT INTO db.table (col1, col2,col3,col4) VALUES ('val',2,3,'foo')", + "INSERT INTO db.table ( col1, col2,col3,col4 ) VALUES ('val',2,3,'foo')" }; const std::vector exp_results { @@ -86,7 +94,15 @@ const std::vector exp_results { "SELECT * FROM tablename WHERE id IN (?,?,?,...)", "SELECT * FROM tablename WHERE id IN (?,?,?,...)", // invalid request grouping - "SELECT * tablename where id IN (?,?,?,... AND j in (?,?,?,... and k=?" + "SELECT * tablename where id IN (?,?,?,... AND j in (?,?,?,... and k=?", + // random insert queries + "INSERT INTO db.table(col1) VALUES (?)", + "INSERT INTO db.table (col1) VALUES (?)", + "INSERT INTO db.table( col1) VALUES ( ? )", + "INSERT INTO db.table( col1) VALUES ( ? )", + "INSERT INTO db.table ( col1 ) VALUES ( ? )", + "INSERT INTO db.table (col1,col2,col3,col4) VALUES (?,?,?,?)", + "INSERT INTO db.table ( col1,col2,col3,col4 ) VALUES (?,?,?,?)" }; const std::vector queries_grouping { From 11d9f475b416c1cd37b4a7d8878dddc2fcb35b59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Fri, 23 Oct 2020 21:09:32 +0200 Subject: [PATCH 3/3] Removed unnecessary indents in 'test_tokenizer-t' --- test/tap/tests/test_tokenizer-t.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/tap/tests/test_tokenizer-t.cpp b/test/tap/tests/test_tokenizer-t.cpp index d528d3cfa..a1ef73f88 100644 --- a/test/tap/tests/test_tokenizer-t.cpp +++ b/test/tap/tests/test_tokenizer-t.cpp @@ -183,10 +183,10 @@ int main(int argc, char** argv) { const auto& query = queries_grouping[i]; const auto& exp_res = increase_mark_num(exp_queries_grouping[i], j); - + char* c_res = mysql_query_digest_and_first_comment(const_cast(query.c_str()), query.length(), NULL, buf); std::string result(c_res); - + ok(result == exp_res, "Grouping digest should be equal to exp result: '%s' == '%s'", result.c_str(), exp_res.c_str()); } }