Skip to content

Fix #1323: multi-statement parser ignores delimiters inside quoted strings#1360

Open
cobyfrombrooklyn-bot wants to merge 1 commit intogolang-migrate:masterfrom
cobyfrombrooklyn-bot:fix-issue-1323
Open

Fix #1323: multi-statement parser ignores delimiters inside quoted strings#1360
cobyfrombrooklyn-bot wants to merge 1 commit intogolang-migrate:masterfrom
cobyfrombrooklyn-bot:fix-issue-1323

Conversation

@cobyfrombrooklyn-bot
Copy link

The splitWithDelimiter function used bytes.Index to find delimiters, which incorrectly splits on semicolons inside single-quoted or double-quoted strings. This breaks migrations containing string literals with semicolons, like ClickHouse SETTINGS(format_csv_delimiter = ';').

Fix

Added findDelimiterOutsideQuotes that tracks quote state (single and double quotes) and only matches delimiters outside of strings. Also handles SQL-style escaped quotes ('').

Test

Added 4 test cases to TestParse:

Without the fix, the parser splits SELECT 'hello;world' into two statements. With the fix, it correctly treats it as one.

Full test suite passes on macOS ARM (Apple Silicon).

Fixes #1323

The splitWithDelimiter function used a naive bytes.Index to find
delimiters, which would incorrectly split on semicolons inside
single-quoted or double-quoted strings (e.g. SETTINGS(format_csv_delimiter = ';')).

Added findDelimiterOutsideQuotes that tracks quote state and only
matches delimiters outside of strings. Also handles SQL-style
escaped quotes ('').

Fixes golang-migrate#1323
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.

Semicolon in string is not allowed with x-multi-statement option

1 participant