From 858b366d8fea37424f4f6b3b534190ac873b02c9 Mon Sep 17 00:00:00 2001 From: JacekPliszka Date: Thu, 12 Feb 2015 00:00:23 +0100 Subject: Fix pathological case of empty statement --- sqlparse/filters.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'sqlparse') diff --git a/sqlparse/filters.py b/sqlparse/filters.py index 7b9b5e7..9c0a476 100644 --- a/sqlparse/filters.py +++ b/sqlparse/filters.py @@ -271,7 +271,11 @@ class StripWhitespaceFilter: [self.process(stack, sgroup, depth + 1) for sgroup in stmt.get_sublists()] self._stripws(stmt) - if depth == 0 and stmt.tokens[-1].is_whitespace(): + if ( + depth == 0 + and stmt.tokens + and stmt.tokens[-1].is_whitespace() + ): stmt.tokens.pop(-1) -- cgit v1.2.1 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 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'sqlparse') 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 -- cgit v1.2.1