Escape backslashes in re.sub()'s repl

This commit is contained in:
RumovZ 2021-03-03 09:20:02 +01:00
parent c0d77896da
commit e2940de4a4

View file

@ -66,7 +66,12 @@ class SidebarItemType(Enum):
return self in self.section_roots() return self in self.section_roots()
def is_editable(self) -> bool: def is_editable(self) -> bool:
return self in (SidebarItemType.SAVED_SEARCH, SidebarItemType.DECK, SidebarItemType.TAG) return self in (
SidebarItemType.SAVED_SEARCH,
SidebarItemType.DECK,
SidebarItemType.TAG,
)
class SidebarStage(Enum): class SidebarStage(Enum):
ROOT = auto() ROOT = auto()
@ -1187,7 +1192,9 @@ class SidebarTreeView(QTreeView):
def rename_node(self, item: SidebarItem, text: str) -> bool: def rename_node(self, item: SidebarItem, text: str) -> bool:
if text.replace('"', ""): if text.replace('"', ""):
new_name = re.sub(re.escape(item.name) + "$", text, item.full_name) new_name = re.sub(
re.escape(item.name) + "$", text.replace("\\", r"\\"), item.full_name
)
if item.item_type == SidebarItemType.DECK: if item.item_type == SidebarItemType.DECK:
self.rename_deck(item, new_name) self.rename_deck(item, new_name)
if item.item_type == SidebarItemType.SAVED_SEARCH: if item.item_type == SidebarItemType.SAVED_SEARCH: