From 93a7a89cf63e21fb60e7dbc8be9efdfd05328ce1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Tue, 5 Sep 2023 17:53:27 +0200 Subject: [PATCH] [formatter] use value of last alternative (#4492) fixes {fieldname|''} evaluating to the value of 'keywords-default' instead of an empty string --- gallery_dl/formatter.py | 5 +++-- test/test_formatter.py | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/gallery_dl/formatter.py b/gallery_dl/formatter.py index 98ea186f..6098fc61 100644 --- a/gallery_dl/formatter.py +++ b/gallery_dl/formatter.py @@ -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 diff --git a/test/test_formatter.py b/test/test_formatter.py index 0992f4ba..dbdccba1 100644 --- a/test/test_formatter.py +++ b/test/test_formatter.py @@ -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())