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, '')