diff --git a/gallery_dl/util.py b/gallery_dl/util.py index d1bba5d4..91fa0a61 100644 --- a/gallery_dl/util.py +++ b/gallery_dl/util.py @@ -382,11 +382,11 @@ class Formatter(): def _apply(self, key, funcs, fmt): def wrap(obj): - if key in obj: + try: obj = obj[key] for func in funcs: obj = func(obj) - else: + except Exception: obj = self.default return fmt(obj) return wrap diff --git a/test/test_util.py b/test/test_util.py index 1d5646d4..3a87757a 100644 --- a/test/test_util.py +++ b/test/test_util.py @@ -188,11 +188,17 @@ class TestFormatter(unittest.TestCase): def test_missing(self): replacement = "None" + self._run_test("{missing}", replacement) self._run_test("{missing.attr}", replacement) self._run_test("{missing[key]}", replacement) self._run_test("{missing:?a//}", "") + self._run_test("{name[missing]}", replacement) + self._run_test("{name[missing].attr}", replacement) + self._run_test("{name[missing][key]}", replacement) + self._run_test("{name[missing]:?a//}", "") + def test_missing_custom_default(self): replacement = default = "foobar" self._run_test("{missing}" , replacement, default)