#28121: force_text incorrectly handles SafeBytes under PY3
------------------------------------+--------------------------------------
Reporter: Thomas Achtemichuk | Owner: nobody
Type: Bug | Status: closed
Component: Utilities | Version: master
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------------+--------------------------------------
Comment (by Thomas Achtemichuk):
Tim,
This came up when bootstrapping a SPA's template with the output of DRF's
`JSONRenderer` which produces utf-8 encoded json. Something like the
following:
{{{
def app_home(request):
return render(
request,
'app_base.html',
{'init_data':
mark_safe(JSONRenderer().render(SomeSerializer.data))}
)
}}}
We're preparing to switch over to python3, and this bug has lead to a
fairly extensive audit of everywhere we use `mark_safe` and pass values
into templates.
Is it certain that the that text version of an arbitrary bytestring is
also safe
If it isn't, then the way that `force_text` has behaved under PY2 for the
last 5+ years should be examined:
{{{
>>> type(force_text(SafeBytes(b'&')))
django.utils.safestring.SafeText
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28121#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.cfcb34441fa2d388d473a25bd7a96141%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.