diff options
| author | Andi Albrecht <albrecht.andi@gmail.com> | 2013-01-25 20:29:21 +0100 |
|---|---|---|
| committer | Andi Albrecht <albrecht.andi@gmail.com> | 2013-01-25 20:29:21 +0100 |
| commit | 07ef26a1a3b7e2b93d855970b92c985328eef097 (patch) | |
| tree | cfd761d28191aa993668a40038e033c2259df9fa | |
| parent | 1584b2225a8d81366ab0298d21b341969c603e8d (diff) | |
| download | sqlparse-07ef26a1a3b7e2b93d855970b92c985328eef097.tar.gz | |
Fix a regression where reindent filter failed when comments contained non-ascii chars.
| -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 |
