Skip to content

Commit 703aec1

Browse files
committed
Fix of problem with multiline treated as stackable while /* /* */ is one comment, not two stacked
1 parent 858b366 commit 703aec1

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

sqlparse/lexer.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,13 @@ def get_tokens_unprocessed(self, stream, stack=('root',)):
315315
statestack.pop()
316316
elif state == '#push':
317317
statestack.append(statestack[-1])
318-
else:
318+
elif (
319+
# Ugly hack - multiline-comments
320+
# are not stackable
321+
state != 'multiline-comments'
322+
or not statestack
323+
or statestack[-1] != 'multiline-comments'
324+
):
319325
statestack.append(state)
320326
elif isinstance(new_state, int):
321327
# pop

tests/test_format.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ def test_strip_comments_multi(self):
6161
sql = 'select (/* sql starts here */ select 2)'
6262
res = sqlparse.format(sql, strip_comments=True)
6363
self.ndiffAssertEqual(res, 'select (select 2)')
64+
sql = 'select (/* sql /* starts here */ select 2)'
65+
res = sqlparse.format(sql, strip_comments=True)
66+
self.ndiffAssertEqual(res, 'select (select 2)')
6467

6568
def test_strip_ws(self):
6669
f = lambda sql: sqlparse.format(sql, strip_whitespace=True)

0 commit comments

Comments
 (0)