From a3bb51993fe9c13e61f3ec5f4f637276adff447e Mon Sep 17 00:00:00 2001 From: Philipp Wolfer Date: Fri, 8 May 2020 14:34:11 +0200 Subject: [PATCH] PICARD-1813: Fixed calling $title with empty value --- picard/script.py | 2 ++ test/test_script.py | 1 + 2 files changed, 3 insertions(+) diff --git a/picard/script.py b/picard/script.py index fbc6222e6..28c9e446d 100644 --- a/picard/script.py +++ b/picard/script.py @@ -1048,6 +1048,8 @@ def func_title(parser, text): like: from "Lost in the Supermarket" to "Lost In The Supermarket" Example: $set(album,$title(%album%)) """ + if not text: + return text capitalized = text[0].capitalize() capital = False for i in range(1, len(text)): diff --git a/test/test_script.py b/test/test_script.py index e41738781..785832608 100644 --- a/test/test_script.py +++ b/test/test_script.py @@ -546,6 +546,7 @@ class ScriptParserTest(PicardTestCase): self.assertScriptResultEquals("$title('a)", "'a") self.assertScriptResultEquals("$title(l'a)", "L'a") self.assertScriptResultEquals("$title(2'a)", "2'A") + self.assertScriptResultEquals(r"$title(%empty%)", "") # Tests wrong number of arguments areg = r"^\d+:\d+:\$title: Wrong number of arguments for \$title: Expected exactly 1, " with self.assertRaisesRegex(ScriptError, areg):