From 703aec1fb30dcf5c0ed14552e601e4487707435e Mon Sep 17 00:00:00 2001 From: JacekPliszka Date: Thu, 12 Feb 2015 01:37:46 +0100 Subject: Fix of problem with multiline treated as stackable while /* /* */ is one comment, not two stacked --- sqlparse/lexer.py | 8 +++++++- tests/test_format.py | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/sqlparse/lexer.py b/sqlparse/lexer.py index a60c789..3e9a1a6 100644 --- a/sqlparse/lexer.py +++ b/sqlparse/lexer.py @@ -315,7 +315,13 @@ class Lexer(object): statestack.pop() elif state == '#push': statestack.append(statestack[-1]) - else: + elif ( + # Ugly hack - multiline-comments + # are not stackable + state != 'multiline-comments' + or not statestack + or statestack[-1] != 'multiline-comments' + ): statestack.append(state) elif isinstance(new_state, int): # pop diff --git a/tests/test_format.py b/tests/test_format.py index b789b17..a105b1c 100644 --- a/tests/test_format.py +++ b/tests/test_format.py @@ -61,6 +61,9 @@ class TestFormat(TestCaseBase): sql = 'select (/* sql starts here */ select 2)' res = sqlparse.format(sql, strip_comments=True) self.ndiffAssertEqual(res, 'select (select 2)') + sql = 'select (/* sql /* starts here */ select 2)' + res = sqlparse.format(sql, strip_comments=True) + self.ndiffAssertEqual(res, 'select (select 2)') def test_strip_ws(self): f = lambda sql: sqlparse.format(sql, strip_whitespace=True) -- cgit v1.2.1