Skip to content

Ignore statements containing only semicolons or whitespace#501

Merged
bgunebakan merged 1 commit into
crate:mainfrom
SAY-5:fix-empty-statement-crash
Jun 16, 2026
Merged

Ignore statements containing only semicolons or whitespace#501
bgunebakan merged 1 commit into
crate:mainfrom
SAY-5:fix-empty-statement-crash

Conversation

@SAY-5

@SAY-5 SAY-5 commented May 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #499.

Submitting a statement that contains only ; (or only whitespace/comments) crashed crash with IndexError: list index out of range from stmt_type(), since re.findall(r'[\w]+', ...) returns an empty list.

_process_sql now skips statements that have no word characters after stripping comments, so an empty line is written instead of crashing.

Added a regression test in MultipleStatementsTest.

Comment thread tests/test_commands.py
cmd._exec = Mock()
cmd.process(";")
cmd.process(";;\n;")
cmd.process(" \n\t")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we also add a test with only comments and maybe spanning multiple lines?

@SAY-5 SAY-5 force-pushed the fix-empty-statement-crash branch from 78bad1c to 0bb8b68 Compare June 11, 2026 19:23
@SAY-5

SAY-5 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

Added test_statement_with_only_comments in 0bb8b68 covering a single-line comment, two comment lines, and a multi-line /* */ block, all asserting nothing gets executed. Confirmed it fails without the skip in _process_sql.

@matriv matriv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@bgunebakan bgunebakan self-requested a review June 16, 2026 10:37

@bgunebakan bgunebakan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution!

@bgunebakan bgunebakan merged commit 2cdd6f4 into crate:main Jun 16, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash crashes when handling a statement with semicolons only

3 participants