Commit 4c893129 authored by unknown's avatar unknown

Improve "check_eol_junk" to detect junk although there are multi line comments in the way.

I.e take advantage of the fact that a # comment is always terminated by a new line 
Add tests for the above


client/mysqltest.c:
  Improve "check_eol_junk" to detect junk although there are multi line comments in the way.
  I.e take advantage of the fact that a # comment is always terminated by a new line
mysql-test/r/mysqltest.result:
  Update resut file
mysql-test/t/mysqltest.test:
  Add test for improved check_eol_junk
parent 95e32915
......@@ -3578,17 +3578,15 @@ void scan_command_for_warnings(struct st_command *command)
/*
Check for unexpected "junk" after the end of query
This is normally caused by missing delimiters
This is normally caused by missing delimiters or when
switching between different delimiters
*/
void check_eol_junk(const char *eol)
void check_eol_junk_line(const char *line)
{
const char *p= eol;
DBUG_ENTER("check_eol_junk");
DBUG_PRINT("enter", ("eol: %s", eol));
/* Remove all spacing chars except new line */
while (*p && my_isspace(charset_info, *p) && (*p != '\n'))
p++;
const char *p= line;
DBUG_ENTER("check_eol_junk_line");
DBUG_PRINT("enter", ("line: %s", line));
/* Check for extra delimiter */
if (*p && !strncmp(p, delimiter, delimiter_length))
......@@ -3604,6 +3602,36 @@ void check_eol_junk(const char *eol)
DBUG_VOID_RETURN;
}
void check_eol_junk(const char *eol)
{
const char *p= eol;
DBUG_ENTER("check_eol_junk");
DBUG_PRINT("enter", ("eol: %s", eol));
/* Skip past all spacing chars and comments */
while (*p && (my_isspace(charset_info, *p) || *p == '#' || *p == '\n'))
{
/* Skip past comments started with # and ended with newline */
if (*p && *p == '#')
{
p++;
while (*p && *p != '\n')
p++;
}
/* Check this line */
if (*p && *p == '\n')
check_eol_junk_line(p);
if (*p)
p++;
}
check_eol_junk_line(p);
DBUG_VOID_RETURN;
}
/*
......
......@@ -152,6 +152,23 @@ mysqltest: At line 1: Missing delimiter
mysqltest: At line 1: End of line junk detected: "sleep 7
# Another comment
"
mysqltest: At line 1: Missing delimiter
mysqltest: At line 1: Missing delimiter
mysqltest: At line 1: End of line junk detected: "disconnect default
#
# comment
# comment2
# comment 3
--disable_query_log
"
mysqltest: At line 1: End of line junk detected: "disconnect default # comment
# comment part2
# comment 3
--disable_query_log
"
mysqltest: At line 1: Extra delimiter ";" found
mysqltest: At line 1: Extra delimiter ";" found
mysqltest: At line 1: Missing argument(s) to 'error'
......
......@@ -359,9 +359,11 @@ select 3 from t1 ;
# Missing delimiter
# The comment will be "sucked into" the sleep command since
# delimiter is missing until after "show status"
--system echo "sleep 4" > $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--system echo "# A comment" >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--system echo "show status;" >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
sleep 4
# A comment
show status;
EOF
--error 1
--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
......@@ -369,8 +371,68 @@ select 3 from t1 ;
# Missing delimiter until eof
# The comment will be "sucked into" the sleep command since
# delimiter is missing
--system echo "sleep 7" > $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--system echo "# Another comment" >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql
--write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
sleep 7
# Another comment
EOF
--error 1
--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
#
# Missing delimiter until "disable_query_log"
#
--write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
disconnect default
#
# comment
# comment 3
disable_query_log;
EOF
--error 1
--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
#
# Missing delimiter until "disable_query_log"
#
--write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
disconnect default
#
# comment
# comment 3
disable_query_log;
EOF
--error 1
--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
#
# Missing delimiter until eof
#
--write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
disconnect default
#
# comment
# comment2
# comment 3
--disable_query_log
EOF
--error 1
--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
#
# Missing delimiter until eof
#
--write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
disconnect default # comment
# comment part2
# comment 3
--disable_query_log
EOF
--error 1
--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment