1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-11-24 10:37:23 +00:00

Use belach or nh3 for cleaning html (fix for #2874)

This commit is contained in:
Ozzie Isaacs 2023-11-09 17:45:22 +01:00
parent bd71391bfb
commit f78e0ff938

14
cps/editbooks.py Executable file → Normal file
View File

@ -29,7 +29,16 @@ from markupsafe import escape, Markup # dependency of flask
from functools import wraps
try:
from lxml.html.clean import clean_html, Cleaner
from bleach import clean_text as clean_html
BLEACH = True
except ImportError:
try:
from nh3 import clean as clean_html
BLEACH = False
except ImportError:
try:
from lxml.html.clean import clean_html
BLEACH = False
except ImportError:
clean_html = None
@ -992,6 +1001,9 @@ def edit_book_series_index(series_index, book):
def edit_book_comments(comments, book):
modify_date = False
if comments:
if BLEACH:
comments = clean_html(comments, tags=None, attributes=None)
else:
comments = clean_html(comments)
if len(book.comments):
if book.comments[0].text != comments: