Fix clicking on author name in book details panel to search in goodreads not working if author has more than two parts in his name

Fixes #1096 (Encode internet search URLs with spaces as %20 rather than +)
This commit is contained in:
Kovid Goyal 2020-02-09 19:35:57 +05:30
parent d81c912b07
commit 15c6ee80de
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -5,7 +5,7 @@
from __future__ import absolute_import, division, print_function, unicode_literals
from polyglot.builtins import iteritems
from polyglot.urllib import quote_plus
from polyglot.urllib import quote, quote_plus
AUTHOR_SEARCHES = {
'goodreads':
@ -48,17 +48,21 @@ all_book_searches = BOOK_SEARCHES.__iter__
all_author_searches = AUTHOR_SEARCHES.__iter__
def qquote(val):
def qquote(val, use_plus=True):
if not isinstance(val, bytes):
val = val.encode('utf-8')
ans = quote_plus(val)
ans = quote_plus(val) if use_plus else quote(val)
if isinstance(ans, bytes):
ans = ans.decode('utf-8')
return ans
def specialised_quote(template, val):
return qquote(val, 'goodreads.com' not in template)
def url_for(template, data):
return template.format(**{k: qquote(v) for k, v in iteritems(data)})
return template.format(**{k: specialised_quote(template, v) for k, v in iteritems(data)})
def url_for_author_search(key, **kw):