sqlparse.format(sql, strip_whitespace=True) raises an unhandled IndexError for the input "( AS )" (a parenthesis group that ends up with fewer than two tokens). A parsing/formatting call should either handle the input or raise a clear parse error, not fail with list index out of range.
Version: reproduced on current master (commit 60cdc64).
Minimal reproducer:
import sqlparse
sqlparse.format("( AS )", strip_whitespace=True)
Traceback:
Traceback (most recent call last):
(reproducer above)
import sqlparse; sqlparse.format('( AS )', strip_whitespace=True)
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "sqlparse/__init__.py", line 60, in format
return "".join(stack.run(sql, encoding))
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
File "sqlparse/engine/filter_stack.py", line 44, in run
filter_.process(stmt)
~~~~~~~~~~~~~~~^^^^^^
File "sqlparse/filters/others.py", line 126, in process
[self.process(sgroup, depth + 1) for sgroup in stmt.get_sublists()]
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
File "sqlparse/filters/others.py", line 127, in process
self._stripws(stmt)
~~~~~~~~~~~~~^^^^^^
File "sqlparse/filters/others.py", line 88, in _stripws
func(tlist)
~~~~^^^^^^^
File "sqlparse/filters/others.py", line 115, in _stripws_parenthesis
while tlist.tokens[1].is_whitespace:
~~~~~~~~~~~~^^^
IndexError: list index out of range
Cause (from the traceback): _stripws_parenthesis accesses tlist.tokens[1] (and later tokens[-2]) without checking the group length; a parenthesis group with fewer than 2 tokens triggers the IndexError.
Expected: the input is parsed/formatted, or a clear parse error is raised — not an unhandled IndexError.
sqlparse.format(sql, strip_whitespace=True)raises an unhandledIndexErrorfor the input"( AS )"(a parenthesis group that ends up with fewer than two tokens). A parsing/formatting call should either handle the input or raise a clear parse error, not fail withlist index out of range.Version: reproduced on current
master(commit60cdc64).Minimal reproducer:
Traceback:
Cause (from the traceback):
_stripws_parenthesisaccessestlist.tokens[1](and latertokens[-2]) without checking the group length; a parenthesis group with fewer than 2 tokens triggers theIndexError.Expected: the input is parsed/formatted, or a clear parse error is raised — not an unhandled
IndexError.