diff --git a/src/calibre/gui2/actions/add.py b/src/calibre/gui2/actions/add.py
index 4c639ec0bd..cfe65c8c2a 100644
--- a/src/calibre/gui2/actions/add.py
+++ b/src/calibre/gui2/actions/add.py
@@ -11,7 +11,7 @@ from collections import defaultdict
from functools import partial
from qt.core import QApplication, QDialog, QPixmap, QTimer
-from calibre import as_unicode, guess_type
+from calibre import as_unicode, guess_type, prepare_string_for_xml
from calibre.constants import iswindows
from calibre.ebooks import BOOK_EXTENSIONS
from calibre.ebooks.metadata import MetaInformation, normalize_isbn
@@ -574,10 +574,10 @@ class AddAction(InterfaceAction):
merged[author].append(title)
lines = []
for author in sorted(merged, key=sort_key):
- lines.append(author)
- for title in sorted(merged[author], key=sort_key):
- lines.append(' ' + title)
- lines.append('')
+ lines.append(f'{prepare_string_for_xml(author)}
')
+ for title in sorted(merged[author]):
+ lines.append(f'- {prepare_string_for_xml(title)}
')
+ lines.append('
')
pm = ngettext('The following duplicate book was found.',
'The following {} duplicate books were found.',
len(adder.merged_books)).format(len(adder.merged_books))
diff --git a/src/calibre/gui2/dialogs/message_box.py b/src/calibre/gui2/dialogs/message_box.py
index 1b6f4dc11a..64a6e164c2 100644
--- a/src/calibre/gui2/dialogs/message_box.py
+++ b/src/calibre/gui2/dialogs/message_box.py
@@ -494,7 +494,16 @@ class JobError(QDialog): # {{{
if __name__ == '__main__':
from calibre.gui2 import Application, question_dialog
+ from calibre import prepare_string_for_xml
app = Application([])
+ merged = {'Kovid Goyal': ['Waterloo', 'Doomed'], 'Someone Else': ['Some other book ' * 1000]}
+ lines = []
+ for author in sorted(merged):
+ lines.append(f'{prepare_string_for_xml(author)}')
+ for title in sorted(merged[author]):
+ lines.append(f'- {prepare_string_for_xml(title)}
')
+ lines.append('
')
+
print(question_dialog(None, 'title', 'msg goog ',
- det_msg='hi there guy '*1000,
+ det_msg='\n'.join(lines),
show_copy_button=True))