From 357a5c7449f3a1f3d20ee9b091082d16f143d42f Mon Sep 17 00:00:00 2001 From: Alejandro Varas Date: Wed, 10 Sep 2014 12:32:26 -0300 Subject: [PATCH] Fixed TypeError raised by `richtext` template tag --- .../wagtailcore/templatetags/wagtailcore_tags.py | 4 +++- wagtail/wagtailcore/tests/tests.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/wagtail/wagtailcore/templatetags/wagtailcore_tags.py b/wagtail/wagtailcore/templatetags/wagtailcore_tags.py index b68a66d63..c3b660a16 100644 --- a/wagtail/wagtailcore/templatetags/wagtailcore_tags.py +++ b/wagtail/wagtailcore/templatetags/wagtailcore_tags.py @@ -35,4 +35,6 @@ def wagtail_version(): @register.filter def richtext(value): - return mark_safe('
' + expand_db_html(value) + '
') + if value: + return mark_safe('
' + expand_db_html(value) + '
') + return '' diff --git a/wagtail/wagtailcore/tests/tests.py b/wagtail/wagtailcore/tests/tests.py index c53494648..3531a35ae 100644 --- a/wagtail/wagtailcore/tests/tests.py +++ b/wagtail/wagtailcore/tests/tests.py @@ -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, '')