From 333f42945a839896ea4aa59abdae8837b8fcbcab Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 9 May 2021 12:20:53 +0530 Subject: [PATCH] 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) --- src/calibre/ebooks/metadata/sources/identify.py | 5 ++++- src/calibre/gui2/preferences/look_feel.py | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/metadata/sources/identify.py b/src/calibre/ebooks/metadata/sources/identify.py index c73af1f100..8ccfc2944b 100644 --- a/src/calibre/ebooks/metadata/sources/identify.py +++ b/src/calibre/ebooks/metadata/sources/identify.py @@ -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: diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py index 0cc011a798..ea3ff03572 100644 --- a/src/calibre/gui2/preferences/look_feel.py +++ b/src/calibre/gui2/preferences/look_feel.py @@ -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)