Whole file
andialbrecht/sqlparse
The author described this change as “Fix issue with strip_comments causing a syntax error (fixes #425)”. It counts as a record because the check below fails on the code as it stood at 488505f6c and passes on 6c7b89cc8, with nothing else changed between the two runs.
Projectandialbrecht/sqlparse
Fix saved2018-11-21
Sharing licenceBSD-3-Clause · LICENSE
Change size+7 −0
What the code was meant to do, written into the code itself as a save note
Fix issue with strip_comments causing a syntax error (fixes #425)
The change
| 26 | 26 | if (prev_ is None or next_ is None or | |
| 27 | 27 | prev_.is_whitespace or prev_.match(T.Punctuation, '(') or | |
| 28 | 28 | next_.is_whitespace or next_.match(T.Punctuation, ')')): | |
| 29 | + | # Insert a whitespace to ensure the following SQL produces | |
| 30 | + | # a valid SQL. For example: | |
| 31 | + | # | |
| 32 | + | # Before: select a--comment\nfrom foo | |
| 33 | + | # After: select a from foo | |
| 34 | + | if prev_ is not None and next_ is None: | |
| 35 | + | tlist.tokens.insert(tidx, sql.Token(T.Whitespace, ' ')) | |
| 29 | 36 | tlist.tokens.remove(token) | |
| 30 | 37 | else: | |
| 31 | 38 | tlist.tokens[tidx] = sql.Token(T.Whitespace, ' ') |
The check that tells the two apart
fail→pass·tests/test_format.py::TestFormat::test_strip_comments_single
Check file tests/test_format.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it488505f6c448e7eb0e4a1915bdc5b6130d44a68a
Broken version dated2018-08-28
Modulesqlparse.filters.others
Units changedStripCommentsFilter
Fingerprint8776fb0f856e2d6a
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in andialbrecht/sqlparse
- 2026-07-25Fix get_real_name for names with more than two dotted parts (#332)
- 2026-07-22Fix function grouping skipped for lowercase 'as' in CREATE TABLE AS SELECT
- 2025-11-29StatementSplitter
- 2025-11-28StatementSplitter
- 2024-07-15StatementSplitter
- 2024-04-13Raise SQLParseError instead of RecursionError.