diff options
| -rw-r--r-- | sqlparse/filters.py | 4 | ||||
| -rw-r--r-- | tests/test_regressions.py | 8 |
2 files changed, 10 insertions, 2 deletions
diff --git a/sqlparse/filters.py b/sqlparse/filters.py index 2f1c825..e238f69 100644 --- a/sqlparse/filters.py +++ b/sqlparse/filters.py @@ -288,8 +288,8 @@ class ReindentFilter: offset += 1 if (prev and isinstance(prev, sql.Comment) - and (str(prev).endswith('\n') - or str(prev).endswith('\r'))): + and (unicode(prev).endswith('\n') + or unicode(prev).endswith('\r'))): nl = tlist.token_next(token) else: nl = self.nl() diff --git a/tests/test_regressions.py b/tests/test_regressions.py index ba156f0..d6108d5 100644 --- a/tests/test_regressions.py +++ b/tests/test_regressions.py @@ -157,3 +157,11 @@ $_$; ALTER TABLE..... ;""" t = sqlparse.split(sql) assert len(t) == 3 + + +def test_comment_encoding_when_reindent(): + # There was an UnicodeEncodeError in the reindent filter that + # casted every comment followed by a keyword to str. + sql = u'select foo -- Comment containing Ümläuts\nfrom bar' + formatted = sqlparse.format(sql, reindent=True) + assert formatted == sql |
