From 8e0558b80493942dfc414bd786d742bfb70c3b63 Mon Sep 17 00:00:00 2001 From: Nicholas Boyd Isacsson Date: Wed, 16 Oct 2024 16:36:36 +0200 Subject: [PATCH] Apply substitute rules in sequence --- beetsplug/substitute.py | 4 +--- test/plugins/test_substitute.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/beetsplug/substitute.py b/beetsplug/substitute.py index ebf6cacbe..a89d0af16 100644 --- a/beetsplug/substitute.py +++ b/beetsplug/substitute.py @@ -34,9 +34,7 @@ class Substitute(BeetsPlugin): """Do the actual replacing.""" if text: for pattern, replacement in self.substitute_rules: - new_text, subs_made = pattern.subn(replacement, text) - if subs_made > 0: - return new_text + text = pattern.sub(replacement, text) return text else: return "" diff --git a/test/plugins/test_substitute.py b/test/plugins/test_substitute.py index 7ac74d7a0..48014e231 100644 --- a/test/plugins/test_substitute.py +++ b/test/plugins/test_substitute.py @@ -78,3 +78,13 @@ class SubstitutePluginTest(PluginTestCase): ("b", "y"), ], ) + + def test_rules_applied_in_sequence(self): + self.run_substitute( + {"a": "b", "b": "c", "d": "a"}, + [ + ("a", "c"), + ("b", "c"), + ("d", "a"), + ], + )