mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix template bugs introduced by using + instead of '%s'
This commit is contained in:
parent
bd8a206219
commit
f280cc956f
@ -43,9 +43,9 @@ class SafeFormat(string.Formatter):
|
|||||||
ign, v = mi.format_field(key, series_with_index=False)
|
ign, v = mi.format_field(key, series_with_index=False)
|
||||||
if v is None:
|
if v is None:
|
||||||
return ''
|
return ''
|
||||||
if v is '':
|
if v == '':
|
||||||
return ''
|
return ''
|
||||||
return prefix + v + suffix
|
return prefix + unicode(v) + suffix
|
||||||
except:
|
except:
|
||||||
return key
|
return key
|
||||||
|
|
||||||
|
@ -101,7 +101,8 @@ def preprocess_template(template):
|
|||||||
template = template.decode(preferred_encoding, 'replace')
|
template = template.decode(preferred_encoding, 'replace')
|
||||||
return template
|
return template
|
||||||
|
|
||||||
template_value_re = re.compile(r'^([^\|]*(?=\|))(?:\|?)([^\|]*)(?:\|?)((?<=\|).*?)$')
|
template_value_re = re.compile(r'^([^\|]*(?=\|))(?:\|?)([^\|]*)(?:\|?)((?<=\|).*?)$',
|
||||||
|
flags= re.UNICODE)
|
||||||
|
|
||||||
def explode_string_template_value(key):
|
def explode_string_template_value(key):
|
||||||
try:
|
try:
|
||||||
@ -120,7 +121,7 @@ class SafeFormat(string.Formatter):
|
|||||||
try:
|
try:
|
||||||
prefix, key, suffix = explode_string_template_value(key)
|
prefix, key, suffix = explode_string_template_value(key)
|
||||||
if kwargs[key]:
|
if kwargs[key]:
|
||||||
return prefix + kwargs[key] + suffix
|
return prefix + unicode(kwargs[key]) + suffix
|
||||||
return ''
|
return ''
|
||||||
except:
|
except:
|
||||||
return ''
|
return ''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user