length of SafeUnicode inside django template
I noticed that if you pass a variable called some_copy containing a
unicode string into a Django template:
some_copy <type 'unicode'>
some_copy|length <type 'int'>
some_copy|safe <class 'django.utils.safestring.SafeUnicode'>
some_copy|safe|length <class 'django.utils.safestring.SafeString'>
I noticed that the length filter is just calling len() on the input, so
tested importing django.utils.safestring.SafeUnicode on a terminal and it
seems to just return <type 'int'> when you call len(). Is there something
strange here about how the safe filter interacts with other filters? I
know there are notes suggesting not to use other filters after safe as
they could render the output less safe. Also, this code was producing a
bug and no longer contains the calls to safe|length, but I was curious
what was going on.
No comments:
Post a Comment