From 34d6bceec46c5d4234c156ed682573d2e5de474a Mon Sep 17 00:00:00 2001 From: Srinivas Reddy Thatiparthy Date: Sun, 1 Jul 2018 02:19:20 +0530 Subject: Fixed #29500 -- Fixed SQLite function crashes on null values. Co-authored-by: Srinivas Reddy Thatiparthy Co-authored-by: Nick Pope --- tests/backends/sqlite/tests.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/backends/sqlite') diff --git a/tests/backends/sqlite/tests.py b/tests/backends/sqlite/tests.py index c82ed1667d..86723a72d2 100644 --- a/tests/backends/sqlite/tests.py +++ b/tests/backends/sqlite/tests.py @@ -59,6 +59,22 @@ class Tests(TestCase): creation = DatabaseWrapper(settings_dict).creation self.assertEqual(creation._get_test_db_name(), creation.connection.settings_dict['TEST']['NAME']) + def test_regexp_function(self): + tests = ( + ('test', r'[0-9]+', False), + ('test', r'[a-z]+', True), + ('test', None, None), + (None, r'[a-z]+', None), + (None, None, None), + ) + for string, pattern, expected in tests: + with self.subTest((string, pattern)): + with connection.cursor() as cursor: + cursor.execute('SELECT %s REGEXP %s', [string, pattern]) + value = cursor.fetchone()[0] + value = bool(value) if value in {0, 1} else value + self.assertIs(value, expected) + @unittest.skipUnless(connection.vendor == 'sqlite', 'SQLite tests') @isolate_apps('backends') -- cgit v1.3