Skip to content

Instantly share code, notes, and snippets.

@loic
Last active December 19, 2015 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loic/5867688 to your computer and use it in GitHub Desktop.
Save loic/5867688 to your computer and use it in GitHub Desktop.
diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py
index b9caf8b..324adfd 100644
--- a/django/db/backends/sqlite3/base.py
+++ b/django/db/backends/sqlite3/base.py
@@ -19,6 +19,7 @@ from django.db.backends.sqlite3.introspection import DatabaseIntrospection
from django.db.models import fields
from django.db.models.sql import aggregates
from django.utils.dateparse import parse_date, parse_datetime, parse_time
+from django.utils.encoding import force_text
from django.utils.functional import cached_property
from django.utils.safestring import SafeBytes
from django.utils import six
@@ -522,4 +523,4 @@ def _sqlite_format_dtdelta(dt, conn, days, secs, usecs):
return str(dt)
def _sqlite_regexp(re_pattern, re_string):
- return bool(re.search(re_pattern, str(re_string))) if re_string is not None else False
+ return bool(re.search(re_pattern, force_text(re_string))) if re_string is not None else False
diff --git a/tests/lookup/tests.py b/tests/lookup/tests.py
index fe8a5fa..680360e 100644
--- a/tests/lookup/tests.py
+++ b/tests/lookup/tests.py
@@ -625,6 +625,14 @@ class LookupTests(TestCase):
self.assertQuerysetEqual(Season.objects.filter(gt__regex=r'^444$'),
['<Season: 2013>'])
+ def test_regex_non_ascii(self):
+ """
+ Ensure that a regex lookup does not trip on non-ascii characters.
+ """
+ Player.objects.create(name='\u2660')
+ self.assertQuerysetEqual(Player.objects.filter(name__regex='\u2660'),
+ ['<Player: \u2660>'])
+
def test_nonfield_lookups(self):
"""
Ensure that a lookup query containing non-fields raises the proper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment