[formatter] use value of last alternative (#4492)

fixes {fieldname|''} evaluating to the value of 'keywords-default'
instead of an empty string
This commit is contained in:
Mike Fährmann
2023-09-05 17:53:27 +02:00
parent f856987297
commit 93a7a89cf6
2 changed files with 5 additions and 2 deletions

View File

@@ -182,9 +182,10 @@ class StringFormatter():
if obj:
break
except Exception:
pass
obj = None
else:
obj = self.default
if obj is None:
obj = self.default
return fmt(obj)
return wrap

View File

@@ -340,6 +340,8 @@ class TestFormatter(unittest.TestCase):
self._run_test("{'foobar'[:3]}", value)
self._run_test("{z|'foo'}" , value)
self._run_test("{z|''|'foo'}" , value)
self._run_test("{z|''}" , "")
self._run_test("{''|''}" , "")
self._run_test("{_lit[foo]}" , value)
self._run_test("{_lit[foo]!u}" , value.upper())