Kaydet (Commit) 670e8ab7 authored tarafından Malcolm Tredinnick's avatar Malcolm Tredinnick

Fixed #2456 -- Added backslash escaping to addslashes, which is necessary 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
üst 93597d05
...@@ -15,7 +15,7 @@ register = Library() ...@@ -15,7 +15,7 @@ register = Library()
def addslashes(value): def addslashes(value):
"Adds slashes - useful for passing strings to JavaScript, for example." "Adds slashes - useful for passing strings to JavaScript, for example."
return value.replace('"', '\\"').replace("'", "\\'") return value.replace('\\', '\\\\').replace('"', '\\"').replace("'", "\\'")
def capfirst(value): def capfirst(value):
"Capitalizes the first character of the value" "Capitalizes the first character of the value"
......
...@@ -15,6 +15,9 @@ r""" ...@@ -15,6 +15,9 @@ r"""
>>> addslashes('"double quotes" and \'single quotes\'') >>> addslashes('"double quotes" and \'single quotes\'')
'\\"double quotes\\" and \\\'single quotes\\\'' '\\"double quotes\\" and \\\'single quotes\\\''
>>> addslashes(r'\ : backslashes, too')
'\\\\ : backslashes, too'
>>> capfirst('hello world') >>> capfirst('hello world')
'Hello world' 'Hello world'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment