Apply substitute rules in sequence

This commit is contained in:
Nicholas Boyd Isacsson 2024-10-16 16:36:36 +02:00
parent 19eb729db3
commit 8e0558b804
2 changed files with 11 additions and 3 deletions

View file

@ -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 ""

View file

@ -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"),
],
)