Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #2456 -- Added backslash escaping to addslashes, which is neces…

…sary once

you start escaping other things. Thanks, tom@eggdrop.ch.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@3799 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 670e8ab7040b3cb1f04d72a76b2c1fc9a4b3f457 1 parent 93597d0
@malcolmt malcolmt authored
View
2  django/template/defaultfilters.py
@@ -15,7 +15,7 @@
def addslashes(value):
"Adds slashes - useful for passing strings to JavaScript, for example."
- return value.replace('"', '\\"').replace("'", "\\'")
+ return value.replace('\\', '\\\\').replace('"', '\\"').replace("'", "\\'")
def capfirst(value):
"Capitalizes the first character of the value"
View
3  tests/regressiontests/defaultfilters/tests.py
@@ -15,6 +15,9 @@
>>> addslashes('"double quotes" and \'single quotes\'')
'\\"double quotes\\" and \\\'single quotes\\\''
+>>> addslashes(r'\ : backslashes, too')
+'\\\\ : backslashes, too'
+
>>> capfirst('hello world')
'Hello world'
Please sign in to comment.
Something went wrong with that request. Please try again.