django/tests/utils_tests
Aymeric Augustin 3483682749 [1.7.x] Fixed #23831 -- Supported strings escaped by third-party libs in Django.
Refs #7261 -- Made strings escaped by Django usable in third-party libs.

The changes in mark_safe and mark_for_escaping are straightforward. The
more tricky part is to handle correctly objects that implement __html__.

Historically escape() has escaped SafeData. Even if that doesn't seem a
good behavior, changing it would create security concerns. Therefore
support for __html__() was only added to conditional_escape() where this
concern doesn't exist.

Then using conditional_escape() instead of escape() in the Django
template engine makes it understand data escaped by other libraries.

Template filter |escape accounts for __html__() when it's available.
|force_escape forces the use of Django's HTML escaping implementation.

Here's why the change in render_value_in_context() is safe. Before Django
1.7 conditional_escape() was implemented as follows:

    if isinstance(text, SafeData):
        return text
    else:
        return escape(text)

render_value_in_context() never called escape() on SafeData. Therefore
replacing escape() with conditional_escape() doesn't change the
autoescaping logic as it was originally intended.

This change should be backported to Django 1.7 because it corrects a
feature added in Django 1.7.

Thanks mitsuhiko for the report.

Backport of 6d52f6f from master.
2014-12-27 18:26:20 +01:00
..
archives [1.7.x] Fixed #22681 -- Made TarArchive recognize leading directories properly. 2014-06-03 15:03:32 -04:00
eggs
files Whitespace cleanup. 2013-10-10 16:49:20 -04:00
locale/nl/LC_MESSAGES Fixed #9523 -- Restart runserver after translation MO files change 2013-11-02 10:29:07 +01:00
test_module Fixed #21302 -- Fixed unused imports and import *. 2013-11-02 15:24:56 -04:00
__init__.py
models.py Fixed #20094 - Be more careful when checking for Iterator 2013-03-22 17:31:29 +01:00
test_archive.py [1.7.x] Fixed #22681 -- Made TarArchive recognize leading directories properly. 2014-06-03 15:03:32 -04:00
test_autoreload.py [1.7.x] Fixed test failure on Windows. 2014-07-30 14:33:58 -04:00
test_baseconv.py Fixing E302 Errors 2013-11-02 23:48:47 -05:00
test_checksums.py Fixing E302 Errors 2013-11-02 23:48:47 -05:00
test_crypto.py Fixed #21302 -- Fixed unused imports and import *. 2013-11-02 15:24:56 -04:00
test_datastructures.py [1.7.x] Fixed #22338 -- Fixed a test dependent on dictionary key iteration order. 2014-03-30 14:27:05 -04:00
test_dateformat.py Fixed #21756 -- Skipped two timezone-related tests on Windows. 2014-01-12 09:41:57 +01:00
test_dateparse.py [1.7.x] Fixed #22814 -- Allowed ISO-8601 [+-]hh timezone format in parse_datetime 2014-06-25 10:58:23 +02:00
test_datetime_safe.py [1.7.x] Fixed #23998 -- Added datetime.time support to migrations questioner. 2014-12-22 07:26:57 -05:00
test_decorators.py Fixing E302 Errors 2013-11-02 23:48:47 -05:00
test_encoding.py Fixed #21198 -- Prevented invalid use of @python_2_unicode_compatible. 2013-10-13 18:14:04 +02:00
test_feedgenerator.py Refactored code and tests that relied on django.utils.tzinfo. 2013-09-09 22:32:52 +02:00
test_functional.py Fixed #21298 -- Fixed E301 pep8 warnings 2013-10-23 13:45:03 +01:00
test_html.py [1.7.x] Tweaked strip_tags tests to pass on Python 3.3 2014-03-22 14:44:13 +01:00
test_http.py [1.7.x] Fixed #23333 -- Made urlsafe_base64_decode() return proper type on Python 3. 2014-10-08 14:03:46 -04:00
test_ipv6.py Fixing E302 Errors 2013-11-02 23:48:47 -05:00
test_itercompat.py Modified utils_tests for unittest2 discovery. 2013-04-12 15:31:58 -06:00
test_jslex.py [1.7.x] Harmonized some PEP 0263 coding preambles 2014-05-15 20:01:31 +02:00
test_lazyobject.py [1.7.x] Fixed a deprecation warning on Python 3. 2014-03-27 07:01:04 -04:00
test_module_loading.py Fixed #21188 -- Introduced subclasses for to-be-removed-in-django-XX warnings 2014-03-08 09:57:40 +01:00
test_no_submodule.py
test_numberformat.py Modified utils_tests for unittest2 discovery. 2013-04-12 15:31:58 -06:00
test_os_utils.py Stopped using django.utils.unittest in the test suite. 2013-07-01 14:29:33 +02:00
test_regex_helper.py Stopped using django.utils.unittest in the test suite. 2013-07-01 14:29:33 +02:00
test_safestring.py [1.7.x] Fixed #23831 -- Supported strings escaped by third-party libs in Django. 2014-12-27 18:26:20 +01:00
test_simplelazyobject.py Fixed #21840 -- Moved dunder methods from SimpleLazyObject to LazyObject. 2014-03-13 10:03:01 +01:00
test_termcolors.py Fixed E127 pep8 warnings. 2013-12-14 11:59:15 -05:00
test_text.py Fixed #21188 -- Introduced subclasses for to-be-removed-in-django-XX warnings 2014-03-08 09:57:40 +01:00
test_timesince.py Fixed all E226 violations 2013-11-03 10:08:55 -08:00
test_timezone.py [1.7.x] Fixed several flake8 errors, including one where a test wouldn't be run 2014-05-17 13:31:09 -04:00
test_tzinfo.py Fixed #21188 -- Introduced subclasses for to-be-removed-in-django-XX warnings 2014-03-08 09:57:40 +01:00