From 977f07364be4f47d9aa50fffc0f7169e1ba9d674 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sun, 31 Dec 2023 19:48:47 +0100 Subject: [PATCH] Fix for #2961 (empty comment with newline causes error 500 on upload) Language of error message for kobo sync improved --- cps/editbooks.py | 14 ++++++++++---- cps/epub.py | 2 +- cps/kobo.py | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cps/editbooks.py b/cps/editbooks.py index 723f72a3..4b33f15e 100644 --- a/cps/editbooks.py +++ b/cps/editbooks.py @@ -27,8 +27,10 @@ from shutil import copyfile from uuid import uuid4 from markupsafe import escape, Markup # dependency of flask from functools import wraps +from lxml.etree import ParserError try: + # at least bleach 6.0 is needed -> incomplatible change from list arguments to set arguments from bleach import clean_text as clean_html BLEACH = True except ImportError: @@ -1001,10 +1003,14 @@ 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) + try: + if BLEACH: + comments = clean_html(comments, tags=set(), attributes=set()) + else: + comments = clean_html(comments) + except ParserError as e: + log.error("Comments of book {} are corrupted: {}".format(book.id, e)) + comments = "" if len(book.comments): if book.comments[0].text != comments: book.comments[0].text = comments diff --git a/cps/epub.py b/cps/epub.py index 50adba59..ca6820b1 100644 --- a/cps/epub.py +++ b/cps/epub.py @@ -102,7 +102,7 @@ def get_epub_info(tmp_file_path, original_file_name, original_file_extension): elif s == 'date': epub_metadata[s] = tmp[0][:10] else: - epub_metadata[s] = tmp[0] + epub_metadata[s] = tmp[0].strip() else: epub_metadata[s] = 'Unknown' diff --git a/cps/kobo.py b/cps/kobo.py index 061977de..5f8c72e1 100644 --- a/cps/kobo.py +++ b/cps/kobo.py @@ -140,7 +140,7 @@ def convert_to_kobo_timestamp_string(timestamp): # @download_required def HandleSyncRequest(): if not current_user.role_download(): - log.info("User needs download permissions for syncing library with Kobo") + log.info("Users need download permissions for syncing library to Kobo reader") return abort(403) sync_token = SyncToken.SyncToken.from_headers(request.headers) log.info("Kobo library sync request received")