diff options
| -rw-r--r-- | CHANGES | 3 | ||||
| -rw-r--r-- | sqlparse/filters.py | 8 |
2 files changed, 10 insertions, 1 deletions
@@ -15,6 +15,9 @@ Enhancements statements in certain encodings more reliable (issue20). * Improve parsing speed when SQL contains CLOBs or BLOBs (issue86). * Improve formatting of ORDER BY clauses (issue89). + * Formatter now tries to detect runaway indentations caused by + parsing errors or invalid SQL statements. When re-indenting such + statements the formatter flips back to column 0 before going crazy. Other * Documentation updates. diff --git a/sqlparse/filters.py b/sqlparse/filters.py index e238f69..fdb32ac 100644 --- a/sqlparse/filters.py +++ b/sqlparse/filters.py @@ -261,7 +261,13 @@ class ReindentFilter: def nl(self): # TODO: newline character should be configurable - ws = '\n' + (self.char * ((self.indent * self.width) + self.offset)) + space = (self.char * ((self.indent * self.width) + self.offset)) + # Detect runaway indenting due to parsing errors + if len(space) > 200: + # something seems to be wrong, flip back + self.indent = self.offset = 0 + space = (self.char * ((self.indent * self.width) + self.offset)) + ws = '\n' + space return sql.Token(T.Whitespace, ws) def _split_kwds(self, tlist): |
