Fixed TypeError raised by richtext template tag

This commit is contained in:
Alejandro Varas 2014-09-10 12:32:26 -03:00 committed by Karl Hobley
parent 9d9bfc1f08
commit 357a5c7449
2 changed files with 17 additions and 1 deletions

View file

@ -35,4 +35,6 @@ def wagtail_version():
@register.filter
def richtext(value):
return mark_safe('<div class="rich-text">' + expand_db_html(value) + '</div>')
if value:
return mark_safe('<div class="rich-text">' + expand_db_html(value) + '</div>')
return ''

View file

@ -4,6 +4,7 @@ from django.test import TestCase
from django.core.cache import cache
from wagtail.wagtailcore.models import Page, Site
from wagtail.wagtailcore.templatetags.wagtailcore_tags import richtext
from wagtail.wagtailcore.utils import resolve_model_string
from wagtail.tests.models import SimplePage
@ -184,3 +185,16 @@ class TestResolveModelString(TestCase):
@unittest.expectedFailure # Raising LookupError instead
def test_resolve_from_bad_type(self):
self.assertRaises(ValueError, resolve_model_string, resolve_model_string)
class TestRichtextTag(TestCase):
def test_typeerror(self):
"""`richtext` fails when it's called with `value` being not a string
or buffer.
"""
value = None
result = richtext(value)
self.assertEqual(result, '')