From fe41a2b159e2690575cc115fc51d7817ba843cec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Tue, 21 Mar 2023 22:06:54 +0100 Subject: [PATCH] [formatter] support putting keys in quotes i.e. obj["key"] or obj['key'] as in f-strings --- gallery_dl/formatter.py | 2 ++ test/test_formatter.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/gallery_dl/formatter.py b/gallery_dl/formatter.py index 858e89ef..fc36fa2c 100644 --- a/gallery_dl/formatter.py +++ b/gallery_dl/formatter.py @@ -256,6 +256,8 @@ def parse_field_name(field_name): try: if ":" in key: key = _slice(key) + else: + key = key.strip("\"'") except TypeError: pass # key is an integer diff --git a/test/test_formatter.py b/test/test_formatter.py index c6e21a60..22589668 100644 --- a/test/test_formatter.py +++ b/test/test_formatter.py @@ -128,6 +128,11 @@ class TestFormatter(unittest.TestCase): self._run_test("{l[0]}" , "a") self._run_test("{a[6]}" , "w") + def test_dict_access(self): + self._run_test("{d[a]}" , "foo") + self._run_test("{d['a']}", "foo") + self._run_test('{d["a"]}', "foo") + def test_slicing(self): v = self.kwdict["a"] self._run_test("{a[1:10]}" , v[1:10])