From 3406e6e489db0e9530ebafde5fe1f53607cbe098 Mon Sep 17 00:00:00 2001 From: Vladimir Katushenok Date: Sat, 14 Dec 2024 16:20:03 +1100 Subject: [PATCH] Escape folder path in selectors --- src/folderOverview/FolderOverview.ts | 4 ++-- src/functions/styleFunctions.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/folderOverview/FolderOverview.ts b/src/folderOverview/FolderOverview.ts index c11c18d..551287a 100644 --- a/src/folderOverview/FolderOverview.ts +++ b/src/folderOverview/FolderOverview.ts @@ -409,7 +409,7 @@ export class FolderOverview { } getElFromOverview(path: string): HTMLElement | null { - const el = this.listEl.querySelector(`[data-path="${path}"]`) as HTMLElement | null; + const el = this.listEl.querySelector(`[data-path="${CSS.escape(path)}"]`) as HTMLElement | null; return el; } @@ -464,4 +464,4 @@ class CustomMarkdownRenderChild extends MarkdownRenderChild { onunload() { this.folderOverview.disconnectListeners(); } -} \ No newline at end of file +} diff --git a/src/functions/styleFunctions.ts b/src/functions/styleFunctions.ts index ccef5c3..8b93691 100644 --- a/src/functions/styleFunctions.ts +++ b/src/functions/styleFunctions.ts @@ -125,7 +125,7 @@ export async function addCSSClassToTitleEL(path: string, cssClass: string, plugi return; } fileExplorerItem.addClass(cssClass); - const viewHeaderItems = document.querySelectorAll(`[data-path="${path}"]`); + const viewHeaderItems = document.querySelectorAll(`[data-path="${CSS.escape(path)}"]`); viewHeaderItems.forEach((item) => { item.addClass(cssClass); }); @@ -134,7 +134,7 @@ export async function addCSSClassToTitleEL(path: string, cssClass: string, plugi export function removeCSSClassFromEL(path: string | undefined, cssClass: string, plugin: FolderNotesPlugin) { if (!path) return; const fileExplorerItem = getEl(path, plugin); - const viewHeaderItems = document.querySelectorAll(`[data-path="${path}"]`); + const viewHeaderItems = document.querySelectorAll(`[data-path="${CSS.escape(path)}"]`); viewHeaderItems.forEach((item) => { item.removeClass(cssClass); }); @@ -152,4 +152,4 @@ export function getEl(path: string, plugin: FolderNotesPlugin): HTMLElement | nu if (!fileExplorerItem) { return null; } if (fileExplorerItem.selfEl) return fileExplorerItem.selfEl; return fileExplorerItem.titleEl; -} \ No newline at end of file +}