diff --git a/src/infi/clickhouse_orm/utils.py b/src/infi/clickhouse_orm/utils.py index e7d6521..c24a93d 100644 --- a/src/infi/clickhouse_orm/utils.py +++ b/src/infi/clickhouse_orm/utils.py @@ -73,8 +73,8 @@ def parse_array(array_string): else: # Start of non-quoted value, find its end match = re.search(r",|\]", array_string) - values.append(array_string[1 : match.start() + 1]) - array_string = array_string[match.end():] + values.append(array_string[0 : match.start()]) + array_string = array_string[match.end() - 1:] def import_submodules(package_name): diff --git a/tests/test_array_fields.py b/tests/test_array_fields.py index ef3c3c1..ba4e94b 100644 --- a/tests/test_array_fields.py +++ b/tests/test_array_fields.py @@ -46,6 +46,21 @@ class ArrayFieldsTest(unittest.TestCase): with self.assertRaises(ValueError): instance.arr_int = value + def test_parse_array(self): + from infi.clickhouse_orm.utils import parse_array, unescape + self.assertEquals(parse_array("[]"), []) + self.assertEquals(parse_array("[1, 2, 395, -44]"), ["1", "2", "395", "-44"]) + self.assertEquals(parse_array("['big','mouse','','!']"), ["big", "mouse", "", "!"]) + self.assertEquals(parse_array(unescape("['\\r\\n\\0\\t\\b']")), ["\r\n\0\t\b"]) + for s in ("", + "[", + "]", + "[1, 2", + "3, 4]", + "['aaa', 'aaa]"): + with self.assertRaises(ValueError): + parse_array(s) + class ModelWithArrays(Model):