summaryrefslogtreecommitdiff
path: root/django/utils/encoding.py
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-11-14 12:58:53 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-11-14 12:58:53 +0000
commit356662cf74c99fac90afb0f5e6aac8d2d573e62a (patch)
tree6ee45dfcb9c91e1184dcc73751e0b856892451ed /django/utils/encoding.py
parentbabfe78494028415b0e5f74ec2ca9b66506e8d34 (diff)
Implemented auto-escaping of variable output in templates. Fully controllable by template authors and it's possible to write filters and templates that simulataneously work in both auto-escaped and non-auto-escaped environments if you need to. Fixed #2359
See documentation in templates.txt and templates_python.txt for how everything works. Backwards incompatible if you're inserting raw HTML output via template variables. Based on an original design from Simon Willison and with debugging help from Michael Radziej. git-svn-id: http://code.djangoproject.com/svn/django/trunk@6671 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils/encoding.py')
-rw-r--r--django/utils/encoding.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/django/utils/encoding.py b/django/utils/encoding.py
index 4bda9caa50..2ab0db7432 100644
--- a/django/utils/encoding.py
+++ b/django/utils/encoding.py
@@ -3,6 +3,7 @@ import urllib
import datetime
from django.utils.functional import Promise
+from django.utils.safestring import SafeData, mark_safe
class DjangoUnicodeDecodeError(UnicodeDecodeError):
def __init__(self, obj, *args):
@@ -51,7 +52,10 @@ def force_unicode(s, encoding='utf-8', strings_only=False, errors='strict'):
else:
s = unicode(str(s), encoding, errors)
elif not isinstance(s, unicode):
- s = unicode(s, encoding, errors)
+ # Note: We use .decode() here, instead of unicode(s, encoding,
+ # errors), so that if s is a SafeString, it ends up being a
+ # SafeUnicode at the end.
+ s = s.decode(encoding, errors)
except UnicodeDecodeError, e:
raise DjangoUnicodeDecodeError(s, *e.args)
return s