summaryrefslogtreecommitdiff
path: root/sqlparse
diff options
context:
space:
mode:
authorFredy Wijaya <fredy.wijaya@gmail.com>2018-11-21 18:05:53 -0600
committerFredy Wijaya <fredy.wijaya@gmail.com>2018-11-21 18:11:28 -0600
commit6c7b89cc8ddbe3159befb4616b70384bf491a29e (patch)
tree0f849547abe102874d01362eed354625732f9a69 /sqlparse
parent488505f6c448e7eb0e4a1915bdc5b6130d44a68a (diff)
downloadsqlparse-6c7b89cc8ddbe3159befb4616b70384bf491a29e.tar.gz
Fix issue with strip_comments causing a syntax error (fixes #425)
Diffstat (limited to 'sqlparse')
-rw-r--r--sqlparse/filters/others.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/sqlparse/filters/others.py b/sqlparse/filters/others.py
index df4d861..b0bb898 100644
--- a/sqlparse/filters/others.py
+++ b/sqlparse/filters/others.py
@@ -26,6 +26,13 @@ class StripCommentsFilter(object):
if (prev_ is None or next_ is None or
prev_.is_whitespace or prev_.match(T.Punctuation, '(') or
next_.is_whitespace or next_.match(T.Punctuation, ')')):
+ # Insert a whitespace to ensure the following SQL produces
+ # a valid SQL. For example:
+ #
+ # Before: select a--comment\nfrom foo
+ # After: select a from foo
+ if prev_ is not None and next_ is None:
+ tlist.tokens.insert(tidx, sql.Token(T.Whitespace, ' '))
tlist.tokens.remove(token)
else:
tlist.tokens[tidx] = sql.Token(T.Whitespace, ' ')