From cf4d0d846c48b2853929de5ad2f06b64e91cd303 Mon Sep 17 00:00:00 2001 From: gabrieljablonski Date: Sat, 13 Apr 2024 14:11:34 -0300 Subject: [PATCH] fix: escape single quotes from `data-tooltip-id` selector --- src/components/Tooltip/Tooltip.tsx | 4 ++-- src/components/TooltipController/TooltipController.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/Tooltip/Tooltip.tsx b/src/components/Tooltip/Tooltip.tsx index a35b5017..dd387bbb 100644 --- a/src/components/Tooltip/Tooltip.tsx +++ b/src/components/Tooltip/Tooltip.tsx @@ -646,7 +646,7 @@ const Tooltip = ({ useEffect(() => { let selector = imperativeOptions?.anchorSelect ?? anchorSelect ?? '' if (!selector && id) { - selector = `[data-tooltip-id='${id}']` + selector = `[data-tooltip-id='${id.replace(/'/g, "\\'")}']` } const documentObserverCallback: MutationCallback = (mutationList) => { const newAnchors: HTMLElement[] = [] @@ -798,7 +798,7 @@ const Tooltip = ({ useEffect(() => { let selector = imperativeOptions?.anchorSelect ?? anchorSelect if (!selector && id) { - selector = `[data-tooltip-id='${id}']` + selector = `[data-tooltip-id='${id.replace(/'/g, "\\'")}']` } if (!selector) { return diff --git a/src/components/TooltipController/TooltipController.tsx b/src/components/TooltipController/TooltipController.tsx index cfe88d58..f5d06e5a 100644 --- a/src/components/TooltipController/TooltipController.tsx +++ b/src/components/TooltipController/TooltipController.tsx @@ -220,7 +220,7 @@ const TooltipController = React.forwardRef( let selector = anchorSelect if (!selector && id) { - selector = `[data-tooltip-id='${id}']` + selector = `[data-tooltip-id='${id.replace(/'/g, "\\'")}']` } if (selector) { try {