From 35d3d897059f1279d2a8094ef93b8cab49ef75f4 Mon Sep 17 00:00:00 2001 From: BlueGreenMagick <50060875+BlueGreenMagick@users.noreply.github.com> Date: Sun, 3 Jan 2021 17:34:44 +0900 Subject: [PATCH] escape tags when finding notes --- qt/aqt/sidebar.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/qt/aqt/sidebar.py b/qt/aqt/sidebar.py index 28f0a6895..c55091d29 100644 --- a/qt/aqt/sidebar.py +++ b/qt/aqt/sidebar.py @@ -3,6 +3,7 @@ # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html from __future__ import annotations +import re from enum import Enum import aqt @@ -111,7 +112,9 @@ class NewSidebarTreeView(SidebarTreeViewBase): def _rename_tag(self, item: "aqt.browser.SidebarItem") -> None: old_name = item.name - nids = self.col.find_notes("tag:" + old_name) + escaped_name = re.sub(r"[*_\\]", r"\\\g<0>", old_name) + escaped_name = '"{}"'.format(escaped_name.replace('"', '\\"')) + nids = self.col.find_notes("tag:" + escaped_name) if len(nids) == 0: showInfo(tr(TR.BROWSING_TAG_RENAME_WARNING_EMPTY)) return