Django

Code

Changeset 3799

Show
Ignore:
Timestamp:
09/23/06 03:41:09 (2 years ago)
Author:
mtredinnick
Message:

Fixed #2456 -- Added backslash escaping to addslashes, which is necessary once
you start escaping other things. Thanks, tom@eggdrop.ch.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/template/defaultfilters.py

    r3563 r3799  
    1616def addslashes(value): 
    1717    "Adds slashes - useful for passing strings to JavaScript, for example." 
    18     return value.replace('"', '\\"').replace("'", "\\'") 
     18    return value.replace('\\', '\\\\').replace('"', '\\"').replace("'", "\\'") 
    1919 
    2020def capfirst(value): 
  • django/trunk/tests/regressiontests/defaultfilters/tests.py

    r3661 r3799  
    1616'\\"double quotes\\" and \\\'single quotes\\\'' 
    1717 
     18>>> addslashes(r'\ : backslashes, too') 
     19'\\\\ : backslashes, too' 
     20 
    1821>>> capfirst('hello world') 
    1922'Hello world'