Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 authored August 11, 2006
1  AUTHORS
@@ -125,6 +125,7 @@ answer newbie questions, and generally made Django that much better:
125 125
     Ivan Sagalaev (Maniac) <http://www.softwaremaniacs.org/>
126 126
     David Schein
127 127
     sopel
  128
+    Thomas Steinacher <tom@eggdrop.ch>
128 129
     Radek Švarz <http://www.svarz.cz/translate/>
129 130
     Swaroop C H <http://www.swaroopch.info>
130 131
     Aaron Swartz <http://www.aaronsw.com/>
2  django/db/models/fields/__init__.py
@@ -20,7 +20,7 @@ class NOT_PROVIDED:
20 20
 BLANK_CHOICE_NONE = [("", "None")]
21 21
 
22 22
 # prepares a value for use in a LIKE query
23  
-prep_for_like_query = lambda x: str(x).replace("%", "\%").replace("_", "\_")
  23
+prep_for_like_query = lambda x: str(x).replace("\\", "\\\\").replace("%", "\%").replace("_", "\_")
24 24
 
25 25
 # returns the <ul> class for a given radio_admin value
26 26
 get_ul_class = lambda x: 'radiolist%s' % ((x == HORIZONTAL) and ' inline' or '')
13  tests/modeltests/lookup/models.py
@@ -15,7 +15,7 @@ class Meta:
15 15
     def __str__(self):
16 16
         return self.headline
17 17
 
18  
-API_TESTS = """
  18
+API_TESTS = r"""
19 19
 # Create a couple of Articles.
20 20
 >>> from datetime import datetime
21 21
 >>> a1 = Article(headline='Article 1', pub_date=datetime(2005, 7, 26))
@@ -161,13 +161,14 @@ def __str__(self):
161 161
 <Article: Article 1>
162 162
 
163 163
 # Underscores and percent signs have special meaning in the underlying
164  
-# database library, but Django handles the quoting of them automatically.
  164
+# SQL code, but Django handles the quoting of them automatically.
165 165
 >>> a8 = Article(headline='Article_ with underscore', pub_date=datetime(2005, 11, 20))
166 166
 >>> a8.save()
167 167
 >>> Article.objects.filter(headline__startswith='Article')
168 168
 [<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>]
169 169
 >>> Article.objects.filter(headline__startswith='Article_')
170 170
 [<Article: Article_ with underscore>]
  171
+
171 172
 >>> a9 = Article(headline='Article% with percent sign', pub_date=datetime(2005, 11, 21))
172 173
 >>> a9.save()
173 174
 >>> Article.objects.filter(headline__startswith='Article')
@@ -182,4 +183,12 @@ def __str__(self):
182 183
 [<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>]
183 184
 >>> Article.objects.exclude(headline="Article 7")
184 185
 [<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>]
  186
+
  187
+# Backslashes also have special meaning in the underlying SQL code, but Django
  188
+# automatically quotes them appropriately.
  189
+>>> a10 = Article(headline='Article with \\ backslash', pub_date=datetime(2005, 11, 22))
  190
+>>> a10.save()
  191
+>>> Article.objects.filter(headline__contains='\\')
  192
+[<Article: Article with \ backslash>]
  193
+
185 194
 """

0 notes on commit 23964a7

Please sign in to comment.
Something went wrong with that request. Please try again.