Escape part of a template string

In ebook-edit, if a filename contains a '%' clicking 'Run check'
results in an error:

Traceback (most recent call last):
  File "/usr/lib/calibre/calibre/gui2/tweak_book/boss.py", line 72, in ans
    return func(*args, **kwargs)
  File "/usr/lib/calibre/calibre/gui2/tweak_book/boss.py", line 1249, in check_requested
    c.run_checks(current_container())
  File "/usr/lib/calibre/calibre/gui2/tweak_book/check.py", line 221, in run_checks
    self.current_item_changed()
  File "/usr/lib/calibre/calibre/gui2/tweak_book/check.py", line 206, in current_item_changed
    template % (err.HELP, ifix, fix_tt, fix_msg, run_tt, run_msg))
ValueError: unsupported format character '_' (0x5f) at index 167
This commit is contained in:
Matthias Rahlf 2018-09-13 16:46:34 +02:00
parent 8785619938
commit f0a925c38d

View File

@ -195,10 +195,12 @@ class Check(QSplitter):
activate = '<div>%s</div>' % ('<br>'.join(activate)) activate = '<div>%s</div>' % ('<br>'.join(activate))
if many: if many:
activate += '<br>' activate += '<br>'
activate = activate.replace('%', '%%')
template = header + ((msg + activate) if many else (activate + msg)) + footer template = header + ((msg + activate) if many else (activate + msg)) + footer
else: else:
activate = '<div><a href="activate:item" title="%s">%s %s</a></div>' % ( activate = '<div><a href="activate:item" title="%s">%s %s</a></div>' % (
open_tt, err.name, loc) open_tt, err.name, loc)
activate = activate.replace('%', '%%')
template = header + activate + msg + footer template = header + activate + msg + footer
self.help.setText( self.help.setText(
template % (err.HELP, ifix, fix_tt, fix_msg, run_tt, run_msg)) template % (err.HELP, ifix, fix_tt, fix_msg, run_tt, run_msg))