Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #2458 -- DB API now properly escapes backslashes, so you don't …

…have to double-escape them. Thanks, tom@eggdrop.ch

git-svn-id: http://code.djangoproject.com/svn/django/trunk@3552 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 23964a7b9a57892c3916ddf6722f74a76072f6e3 1 parent 3e22c8f
Adrian Holovaty adrianholovaty authored
1  AUTHORS
View
@@ -125,6 +125,7 @@ answer newbie questions, and generally made Django that much better:
Ivan Sagalaev (Maniac) <http://www.softwaremaniacs.org/>
David Schein
sopel
+ Thomas Steinacher <tom@eggdrop.ch>
Radek Švarz <http://www.svarz.cz/translate/>
Swaroop C H <http://www.swaroopch.info>
Aaron Swartz <http://www.aaronsw.com/>
2  django/db/models/fields/__init__.py
View
@@ -20,7 +20,7 @@ class NOT_PROVIDED:
BLANK_CHOICE_NONE = [("", "None")]
# prepares a value for use in a LIKE query
-prep_for_like_query = lambda x: str(x).replace("%", "\%").replace("_", "\_")
+prep_for_like_query = lambda x: str(x).replace("\\", "\\\\").replace("%", "\%").replace("_", "\_")
# returns the <ul> class for a given radio_admin value
get_ul_class = lambda x: 'radiolist%s' % ((x == HORIZONTAL) and ' inline' or '')
13 tests/modeltests/lookup/models.py
View
@@ -15,7 +15,7 @@ class Meta:
def __str__(self):
return self.headline
-API_TESTS = """
+API_TESTS = r"""
# Create a couple of Articles.
>>> from datetime import datetime
>>> a1 = Article(headline='Article 1', pub_date=datetime(2005, 7, 26))
@@ -161,13 +161,14 @@ def __str__(self):
<Article: Article 1>
# Underscores and percent signs have special meaning in the underlying
-# database library, but Django handles the quoting of them automatically.
+# SQL code, but Django handles the quoting of them automatically.
>>> a8 = Article(headline='Article_ with underscore', pub_date=datetime(2005, 11, 20))
>>> a8.save()
>>> Article.objects.filter(headline__startswith='Article')
[<Article: Article_ with underscore>, <Article: Article 5>, <Article: Article 6>, <Article: Article 4>, <Article: Article 2>, <Article: Article 3>, <Article: Article 7>, <Article: Article 1>]
>>> Article.objects.filter(headline__startswith='Article_')
[<Article: Article_ with underscore>]
+
>>> a9 = Article(headline='Article% with percent sign', pub_date=datetime(2005, 11, 21))
>>> a9.save()
>>> Article.objects.filter(headline__startswith='Article')
@@ -182,4 +183,12 @@ def __str__(self):
[<Article: Article% with percent sign>, <Article: Article 5>, <Article: Article 6>, <Article: Article 4>, <Article: Article 2>, <Article: Article 3>, <Article: Article 7>, <Article: Article 1>]
>>> Article.objects.exclude(headline="Article 7")
[<Article: Article% with percent sign>, <Article: Article_ with underscore>, <Article: Article 5>, <Article: Article 6>, <Article: Article 4>, <Article: Article 2>, <Article: Article 3>, <Article: Article 1>]
+
+# Backslashes also have special meaning in the underlying SQL code, but Django
+# automatically quotes them appropriately.
+>>> a10 = Article(headline='Article with \\ backslash', pub_date=datetime(2005, 11, 22))
+>>> a10.save()
+>>> Article.objects.filter(headline__contains='\\')
+[<Article: Article with \ backslash>]
+
"""
Please sign in to comment.
Something went wrong with that request. Please try again.