diff --git a/wagtail/wagtailcore/templatetags/wagtailcore_tags.py b/wagtail/wagtailcore/templatetags/wagtailcore_tags.py
index c3b660a16..c0cf66e29 100644
--- a/wagtail/wagtailcore/templatetags/wagtailcore_tags.py
+++ b/wagtail/wagtailcore/templatetags/wagtailcore_tags.py
@@ -35,6 +35,9 @@ def wagtail_version():
@register.filter
def richtext(value):
- if value:
- return mark_safe('
' + expand_db_html(value) + '
')
- return ''
+ if value is not None:
+ html = expand_db_html(value)
+ else:
+ html = ''
+
+ return mark_safe('' + html + '
')
diff --git a/wagtail/wagtailcore/tests/tests.py b/wagtail/wagtailcore/tests/tests.py
index 8759b9f34..71b2b1605 100644
--- a/wagtail/wagtailcore/tests/tests.py
+++ b/wagtail/wagtailcore/tests/tests.py
@@ -1,5 +1,6 @@
from django.test import TestCase
from django.core.cache import cache
+from django.utils.safestring import SafeString
from wagtail.wagtailcore.models import Page, Site
from wagtail.wagtailcore.templatetags.wagtailcore_tags import richtext
@@ -146,13 +147,11 @@ class TestSiteRootPathsCache(TestCase):
class TestRichtextTag(TestCase):
+ def test_call_with_text(self):
+ result = richtext("Hello world!")
+ self.assertEqual(result, 'Hello world!
')
+ self.assertIsInstance(result, SafeString)
- 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, '')
+ def test_call_with_none(self):
+ result = richtext(None)
+ self.assertEqual(result, '')