Clean strings in comments before displaying

This commit is contained in:
Ozzie Isaacs
2026-04-03 09:01:01 +02:00
parent 00686ec1f2
commit 7c715f34dc
5 changed files with 11 additions and 4 deletions

View File

@@ -35,7 +35,7 @@ def clean_string(unsafe_text, book_id=0):
try: try:
if bleach: if bleach:
allowed_tags = list(ALLOWED_TAGS) allowed_tags = list(ALLOWED_TAGS)
allowed_tags.extend(["p", "span", "div", "pre", "br", "h1", "h2", "h3", "h4", "h5", "h6"]) allowed_tags.extend(["p", "span", "div", "pre", "br", "h1", "h2", "h3", "h4", "h5", "h6", "img"])
safe_text = clean_html(unsafe_text, tags=set(allowed_tags)) safe_text = clean_html(unsafe_text, tags=set(allowed_tags))
else: else:
safe_text = clean_html(unsafe_text) safe_text = clean_html(unsafe_text)

View File

@@ -30,6 +30,7 @@ from uuid import uuid4
from flask import Blueprint, request, url_for, g from flask import Blueprint, request, url_for, g
from flask_babel import format_date from flask_babel import format_date
from .cw_login import current_user from .cw_login import current_user
from .clean_html import clean_string as html_clean_string
from . import constants, logger from . import constants, logger
@@ -181,3 +182,9 @@ def contains_music(book_formats):
if format.format.lower() in g.constants.EXTENSIONS_AUDIO: if format.format.lower() in g.constants.EXTENSIONS_AUDIO:
result = True result = True
return result return result
@jinjia.app_template_filter('clean_string')
def clean_string(unsafe_text):
return html_clean_string(unsafe_text)

View File

@@ -74,7 +74,7 @@
{% if entry.comments|length > 0 and entry.comments[0].text|length > 0 %} {% if entry.comments|length > 0 and entry.comments[0].text|length > 0 %}
<div> <div>
<h2 id="decription">{{ _('Description:') }}</h2> <h2 id="decription">{{ _('Description:') }}</h2>
{{ entry.comments[0].text|safe }} {{ entry.comments[0].text|clean_string|safe }}
</div> </div>
{% endif %} {% endif %}
</div> </div>

View File

@@ -284,7 +284,7 @@
{% if entry.comments|length > 0 and entry.comments[0].text|length > 0 %} {% if entry.comments|length > 0 and entry.comments[0].text|length > 0 %}
<div class="comments"> <div class="comments">
<h3 id="decription">{{ _('Description:') }}</h3> <h3 id="decription">{{ _('Description:') }}</h3>
{{ entry.comments[0].text|safe }} {{ entry.comments[0].text|clean_string|safe }}
</div> </div>
{% endif %} {% endif %}

View File

@@ -175,7 +175,7 @@
{% if entry.comments|length > 0 and entry.comments[0].text|length > 0%} {% if entry.comments|length > 0 and entry.comments[0].text|length > 0%}
<div class="comments"> <div class="comments">
<h3 id="decription">{{_('Description:')}}</h3> <h3 id="decription">{{_('Description:')}}</h3>
{{entry.comments[0].text|safe}} {{entry.comments[0].text|clean_string|safe}}
</div> </div>
{% endif %} {% endif %}