Skip to content

Fix IndexError formatting a degenerate parenthesis group#862

Open
santhreal wants to merge 1 commit into
andialbrecht:masterfrom
santhreal:fix/stripws-parenthesis-indexerror
Open

Fix IndexError formatting a degenerate parenthesis group#862
santhreal wants to merge 1 commit into
andialbrecht:masterfrom
santhreal:fix/stripws-parenthesis-indexerror

Conversation

@santhreal

Copy link
Copy Markdown

StripWhitespaceFilter._stripws_parenthesis indexes tokens[1] and tokens[-2], assuming a parenthesis always wraps content between an opening and closing token. Some inputs group otherwise: (::) is grouped as a single Identifier, so the enclosing Parenthesis holds one token and the index raises IndexError.

Repro: sqlparse.format('(::)', reindent=True) (also strip_whitespace=True).

Only strip inner whitespace when there is content between the delimiters. Normal parentheses are unaffected (( a ) -> (a)).

StripWhitespaceFilter._stripws_parenthesis indexes tokens[1] and tokens[-2]
assuming a parenthesis always wraps inner content between an opening and
closing token. Some inputs group otherwise: '(::)' becomes a single
Identifier, so the enclosing Parenthesis holds one token and the index
raises IndexError. Only strip inner whitespace when there is content to
strip.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant