Code

Ticket #8966: 8966_with_docs.diff

File 8966_with_docs.diff, 1.3 KB (added by carljm, 6 years ago)

same patch, with warning note in docs

Line 
1Index: django/template/defaultfilters.py
2===================================================================
3--- django/template/defaultfilters.py   (revision 9103)
4+++ django/template/defaultfilters.py   (working copy)
5@@ -476,7 +476,6 @@
6 def length_is(value, arg):
7     """Returns a boolean of whether the value's length is the argument."""
8     return len(value) == int(arg)
9-length_is.is_safe = True
10 
11 def random(value):
12     """Returns a random item from the list."""
13Index: docs/howto/custom-template-tags.txt
14===================================================================
15--- docs/howto/custom-template-tags.txt (revision 9103)
16+++ docs/howto/custom-template-tags.txt (working copy)
17@@ -241,6 +241,12 @@
18        this tricky, but keep an eye out for any problems like that when
19        reviewing your code.
20 
21+       Marking a filter ``is_safe`` will coerce the filter's return value to
22+       a string.  If your filter should return a boolean or other non-string
23+       value, marking it ``is_safe`` will probably have unintended
24+       consequences (such as converting a boolean False to the string
25+       'False').
26+
27     2. Alternatively, your filter code can manually take care of any necessary
28        escaping. This is necessary when you're introducing new HTML markup into
29        the result. You want to mark the output as safe from further