Skip to content

Commit

Permalink
fix django-cms#7859: allow special characters in page title
Browse files Browse the repository at this point in the history
  • Loading branch information
jrief committed Apr 9, 2024
1 parent c600897 commit a17fe19
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions cms/templatetags/cms_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from django.template.loader import render_to_string
from django.urls import reverse
from django.utils.encoding import smart_str
from django.utils.html import escape
from django.utils.html import escape, strip_tags
from django.utils.http import urlencode
from django.utils.translation import (
get_language,
Expand Down Expand Up @@ -407,7 +407,9 @@ def get_value(self, context, name, page_lookup):
if page and name in self.valid_attributes:
func = getattr(page, "get_%s" % name)
ret_val = func(language=lang, fallback=True)
if not isinstance(ret_val, datetime):
if name == 'page_title':
ret_val = strip_tags(ret_val)
elif not isinstance(ret_val, datetime):
ret_val = escape(ret_val)
return ret_val
return ''
Expand Down
4 changes: 2 additions & 2 deletions cms/tests/test_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from django.test import RequestFactory
from django.test.utils import override_settings
from django.utils.encoding import force_str
from django.utils.html import escape
from django.utils.html import strip_tags
from django.utils.timezone import now
from django.utils.translation import override as force_language
from djangocms_text_ckeditor.cms_plugins import TextPlugin
Expand Down Expand Up @@ -128,7 +128,7 @@ class FakeRequest:
template = '{% load cms_tags %}{% page_attribute page_title %}'
output = self.render_template_obj(template, {}, request)
self.assertNotEqual(script, output)
self.assertEqual(escape(script), output)
self.assertEqual(strip_tags(script), output)

def test_json_encoder(self):
self.assertEqual(json_filter(True), 'true')
Expand Down

0 comments on commit a17fe19

Please sign in to comment.