diff --git a/crates/dbx-core/src/sql.rs b/crates/dbx-core/src/sql.rs index 72f6aece08..e6dd8a744e 100644 --- a/crates/dbx-core/src/sql.rs +++ b/crates/dbx-core/src/sql.rs @@ -1888,6 +1888,10 @@ fn leading_executable_sql_with_options(sql: &str, options: SqlParsingOptions) -> i += 1; } + if i >= bytes.len() { + break; + } + if i + 1 < bytes.len() && bytes[i] == b'-' && bytes[i + 1] == b'-' { i += 2; while i < bytes.len() && bytes[i] != b'\n' { @@ -1931,6 +1935,10 @@ fn first_executable_sql_token_with_options(sql: &str, options: SqlParsingOptions i += 1; } + if i >= bytes.len() { + break; + } + if i + 1 < bytes.len() && bytes[i] == b'-' && bytes[i + 1] == b'-' { i += 2; while i < bytes.len() && bytes[i] != b'\n' { @@ -2419,6 +2427,21 @@ mod tests { ); } + #[test] + fn mysql_split_skips_comment_only_statement() { + assert!(split_sql_statements_for_database("-- DBX SQL preview crash reproducer\n\n;", DatabaseType::Mysql) + .is_empty()); + } + + #[test] + fn mysql_keyword_detection_skips_comment_only_input() { + assert!(!starts_with_executable_sql_keyword_for_database( + "-- DBX SQL preview crash reproducer\n\n", + &["SELECT"], + DatabaseType::Mysql, + )); + } + #[test] fn decodes_utf8_bom_sql_file_bytes_without_bom_statement_prefix() { let sql = decode_sql_file_bytes(b"\xEF\xBB\xBFCREATE TABLE t(id int);").unwrap();