[outtmpl] Fix replacement/default when used with alternate

This commit is contained in:
pukkandan 2022-03-26 07:39:36 +05:30
parent 6db9c4d57d
commit 34baa9fdf0
No known key found for this signature in database
GPG Key ID: 7EEE9E1E817D0A39
2 changed files with 8 additions and 5 deletions

View File

@ -818,6 +818,8 @@ def expect_same_infodict(out):
test('%(id&foo)s.bar', 'foo.bar') test('%(id&foo)s.bar', 'foo.bar')
test('%(title&foo)s.bar', 'NA.bar') test('%(title&foo)s.bar', 'NA.bar')
test('%(title&foo|baz)s.bar', 'baz.bar') test('%(title&foo|baz)s.bar', 'baz.bar')
test('%(x,id&foo|baz)s.bar', 'foo.bar')
test('%(x,title&foo|baz)s.bar', 'baz.bar')
# Laziness # Laziness
def gen(): def gen():

View File

@ -1099,10 +1099,11 @@ def prepare_outtmpl(self, outtmpl, info_dict, sanitize=False):
(?P<fields>{field}) (?P<fields>{field})
(?P<maths>(?:{math_op}{math_field})*) (?P<maths>(?:{math_op}{math_field})*)
(?:>(?P<strf_format>.+?))? (?:>(?P<strf_format>.+?))?
(?P<remaining>
(?P<alternate>(?<!\\),[^|&)]+)? (?P<alternate>(?<!\\),[^|&)]+)?
(?:&(?P<replacement>.*?))? (?:&(?P<replacement>.*?))?
(?:\|(?P<default>.*?))? (?:\|(?P<default>.*?))?
$'''.format(field=FIELD_RE, math_op=MATH_OPERATORS_RE, math_field=MATH_FIELD_RE)) )$'''.format(field=FIELD_RE, math_op=MATH_OPERATORS_RE, math_field=MATH_FIELD_RE))
def _traverse_infodict(k): def _traverse_infodict(k):
k = k.split('.') k = k.split('.')
@ -1173,7 +1174,7 @@ def create_key(outer_mobj):
value = get_value(mobj) value = get_value(mobj)
replacement = mobj['replacement'] replacement = mobj['replacement']
if value is None and mobj['alternate']: if value is None and mobj['alternate']:
mobj = re.match(INTERNAL_FORMAT_RE, mobj['alternate'][1:]) mobj = re.match(INTERNAL_FORMAT_RE, mobj['remaining'][1:])
else: else:
break break