Book details: When creating rules to convert identifiers to URLs allow using {id_unquoted} to avoid quoting the identifier value. Fixes #1927520 [hashtag in identifier breaks url](https://bugs.launchpad.net/calibre/+bug/1927520)

This commit is contained in:
Kovid Goyal 2021-05-09 12:20:53 +05:30
parent 3e1fff5fcf
commit 333f42945a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 10 additions and 2 deletions

View File

@ -553,7 +553,10 @@ def urls_from_identifiers(identifiers, sort_results=False): # {{{
formatter = EvalFormatter()
for k, val in iteritems(identifiers):
val = val.replace('|', ',')
vals = {'id':unicode_type(quote(val if isinstance(val, bytes) else val.encode('utf-8')))}
vals = {
'id':unicode_type(quote(val if isinstance(val, bytes) else val.encode('utf-8'))),
'id_unquoted': str(val),
}
items = rules.get(k) or ()
for name, template in items:
try:

View File

@ -118,6 +118,8 @@ class IdLinksRuleEdit(Dialog):
title = _('Edit rule') if key else _('Create a new rule')
Dialog.__init__(self, title=title, name='id-links-rule-editor', parent=parent)
self.key.setText(key), self.nw.setText(name), self.template.setText(template or 'https://example.com/{id}')
if self.size().height() < self.sizeHint().height():
self.resize(self.sizeHint())
@property
def rule(self):
@ -135,7 +137,10 @@ class IdLinksRuleEdit(Dialog):
self.nw = n = QLineEdit(self)
l.addRow(_('&Name:'), n)
la = QLabel(_(
'The template used to create the link. The placeholder {id} in the template will be replaced with the actual identifier value.'))
'The template used to create the link.'
' The placeholder {0} in the template will be replaced'
' with the actual identifier value. Use {1} to avoid the value'
' being quoted.').format('{id}', '{id_unquoted}'))
la.setWordWrap(True)
l.addRow(la)
self.template = t = QLineEdit(self)