Skip to content

Commit

Permalink
Merge pull request #51 from aminought/master
Browse files Browse the repository at this point in the history
Fix UnicodeDecodeError
  • Loading branch information
xzkostyan committed Mar 5, 2019
2 parents 91453b1 + f898d98 commit c0d2952
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion clickhouse_sqlalchemy/drivers/http/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


def unescape(value):
return codecs.escape_decode(value)[0].decode('utf-8')
return codecs.escape_decode(value)[0].decode('utf-8', errors='replace')


def parse_tsv(line):
Expand Down
10 changes: 7 additions & 3 deletions tests/drivers/http/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
from clickhouse_sqlalchemy.drivers.http.utils import parse_tsv
from clickhouse_sqlalchemy.drivers.http.utils import unescape, parse_tsv
from tests.testcase import BaseTestCase


class HttpUtilsTestCase(BaseTestCase):
test_values = [b'', b'a\tb\tc']
def test_unescape(self):
test_values = [b'', b'a', b'\xff']
actual = [unescape(t) for t in test_values]
assert actual == ['', 'a', '�']

def test_parse_tsv(self):
test_values = [b'', b'a\tb\tc', b'a\tb\t\xff']
try:
for v in self.test_values:
for v in test_values:
parse_tsv(v)
except IndexError:
self.fail('"parse_tsv" raised IndexError exception!')
Expand Down

0 comments on commit c0d2952

Please sign in to comment.