From 643ec35449f3cb85667d409ccf90a0bad22e0940 Mon Sep 17 00:00:00 2001 From: Dave Shifflett Date: Mon, 29 Dec 2014 18:57:38 -0600 Subject: [PATCH] Use alternate pattern match during field changes When a user renames or deletes a field, Anki tries to go through the user's templates to substitute occurrences of that field name with its new name or remove the field. However, if the user has multiple Mustache placeholders on a single line, this does not work as intended because the leading (.*) capture group grabs the text in-between the two (or more) Mustache placeholders. Examples: {{#Flag}} ... {{/Flag}}{{^Flag}} ... {{/Flag}} or {{Front}} {{#Flag}}...{{/Flag}} or {{Front}} Hello. {{Victim}} --- anki/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/anki/models.py b/anki/models.py index bd363514b..6f11bc05f 100644 --- a/anki/models.py +++ b/anki/models.py @@ -304,7 +304,7 @@ and notes.mid = ? and cards.ord = ?""", m['id'], ord) def renameField(self, m, field, newName): self.col.modSchema(check=True) - pat = r'{{(.*)([:#^/]|[^:#/^}][^:}]*?:|)%s}}' + pat = r'{{([^{}]*)([:#^/]|[^:#/^}][^:}]*?:|)%s}}' def wrap(txt): def repl(match): return '{{' + match.group(1) + match.group(2) + txt + '}}'