diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index a2e9d2f405f..cf1d3d5f6d8 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 9b1cfda833c..32d6ef5202b 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'