1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #7261 -- support for __html__ for library interoperability

The idea is that if an object implements __html__ which returns a string this is
used as HTML representation (eg: on escaping). If the object is a str or unicode
subclass and returns itself the object is a safe string type.

This is an updated patch based on jbalogh and ivank patches.
This commit is contained in:
Unai Zalakain
2013-10-15 00:40:52 +02:00
parent ef22d512b5
commit af64429b99
4 changed files with 21 additions and 5 deletions

View File

@@ -5,7 +5,7 @@ from datetime import datetime
import os
from unittest import TestCase
from django.utils import html
from django.utils import html, safestring
from django.utils._os import upath
from django.utils.encoding import force_text
@@ -192,3 +192,9 @@ class TestUtilsHtml(TestCase):
self.assertEqual(quote('http://example.com/path/öäü/'), 'http://example.com/path/%C3%B6%C3%A4%C3%BC/')
self.assertEqual(quote('http://example.com/%C3%B6/ä/'), 'http://example.com/%C3%B6/%C3%A4/')
self.assertEqual(quote('http://example.com/?x=1&y=2'), 'http://example.com/?x=1&y=2')
def test_conditional_escape(self):
s = '<h1>interop</h1>'
self.assertEqual(html.conditional_escape(s),
'&lt;h1&gt;interop&lt;/h1&gt;')
self.assertEqual(html.conditional_escape(safestring.mark_safe(s)), s)