From 670e8ab7040b3cb1f04d72a76b2c1fc9a4b3f457 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Sat, 23 Sep 2006 08:41:09 +0000 Subject: [PATCH] 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 --- django/template/defaultfilters.py | 2 +- tests/regressiontests/defaultfilters/tests.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index a2e9d2f405..cf1d3d5f6d 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -15,7 +15,7 @@ register = Library() 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" diff --git a/tests/regressiontests/defaultfilters/tests.py b/tests/regressiontests/defaultfilters/tests.py index 9b1cfda833..32d6ef5202 100644 --- a/tests/regressiontests/defaultfilters/tests.py +++ b/tests/regressiontests/defaultfilters/tests.py @@ -15,6 +15,9 @@ r""" >>> addslashes('"double quotes" and \'single quotes\'') '\\"double quotes\\" and \\\'single quotes\\\'' +>>> addslashes(r'\ : backslashes, too') +'\\\\ : backslashes, too' + >>> capfirst('hello world') 'Hello world'