﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
28121	force_text incorrectly handles SafeBytes under PY3	Thomas Achtemichuk	nobody	"Under python 3 & Django 1.8.18, 1.9.13, 1.10.7, 1.11 and master, calling `force_text` on an instance of `SafeBytes` causes a `str` to be returned rather than an instance of `SafeText`.

{{{
>>> from django.utils.safestring import SafeBytes, SafeText
>>> from django.utils.encoding import force_text
>>> type(force_text(SafeText('')))
django.utils.safestring.SafeText
>>> type(force_text(SafeBytes(b'')))
str
}}}

This causes byte strings run through `mark_safe` and rendered in a template to be incorrectly escaped.

{{{
>>> from django.template import Template, Context
>>> from django.utils.safestring import mark_safe
>>> Template('{{ x }}').render(Context({'x': mark_safe(b'&')}))
'&amp;'
>>> Template('{{ x }}').render(Context({'x': mark_safe('&')}))
'&'
}}}

Edit: This behavior differs from the same code run under PY2:

{{{
>>> type(force_text(SafeBytes(b'&')))
django.utils.safestring.SafeText
}}}

And disagrees with the comment in force_text:
{{{
            # Note: We use .decode() here, instead of six.text_type(s, encoding,
            # errors), so that if s is a SafeBytes, it ends up being a
            # SafeText at the end.
}}}"	Bug	new	Utilities	1.11	Normal				Unreviewed	0	0	0	0	0	0
