diff --git a/web/src/components/SearchBar.tsx b/web/src/components/SearchBar.tsx index 818fc6190098b..18bfc3792d2d3 100644 --- a/web/src/components/SearchBar.tsx +++ b/web/src/components/SearchBar.tsx @@ -38,7 +38,7 @@ const SearchBar = () => { useEffect(() => { const text = locationStore.getState().query.text; setQueryText(text === undefined ? "" : text); - }, [locationStore.getState().query.text]); + }, [locationStore.state.query.text]); const handleMemoTypeItemClick = (type: MemoSpecType | undefined) => { const { type: prevType } = locationStore.getState().query ?? {}; diff --git a/web/src/labs/highlighter/index.ts b/web/src/labs/highlighter/index.ts index 985f8ac7d2621..d18e6cb159594 100644 --- a/web/src/labs/highlighter/index.ts +++ b/web/src/labs/highlighter/index.ts @@ -1,6 +1,4 @@ -const escapeRegExp = (str: string): string => { - return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); -}; +import { escape } from "lodash"; const walkthroughNodeWithKeyword = (node: HTMLElement, keyword: string) => { if (node.nodeType === 3) { @@ -19,8 +17,8 @@ export const highlightWithWord = (html: string, keyword?: string): string => { if (!keyword) { return html; } - keyword = escapeRegExp(keyword); + keyword = escape(keyword); const wrap = document.createElement("div"); - wrap.innerHTML = html; + wrap.innerHTML = escape(html); return walkthroughNodeWithKeyword(wrap, keyword); }; diff --git a/web/src/labs/marked/parser/Bold.ts b/web/src/labs/marked/parser/Bold.ts index 578a6ed48411e..041640f216dc6 100644 --- a/web/src/labs/marked/parser/Bold.ts +++ b/web/src/labs/marked/parser/Bold.ts @@ -1,3 +1,4 @@ +import { escape } from "lodash"; import { marked } from ".."; import Link from "./Link"; @@ -14,7 +15,7 @@ const renderer = (rawStr: string): string => { return rawStr; } - const parsedContent = marked(matchResult[1], [], [Link]); + const parsedContent = marked(escape(matchResult[1]), [], [Link]); return `${parsedContent}`; }; diff --git a/web/src/labs/marked/parser/BoldEmphasis.ts b/web/src/labs/marked/parser/BoldEmphasis.ts index 0fdf37ebbbe46..f434da5849166 100644 --- a/web/src/labs/marked/parser/BoldEmphasis.ts +++ b/web/src/labs/marked/parser/BoldEmphasis.ts @@ -1,3 +1,4 @@ +import { escape } from "lodash"; import { marked } from ".."; import Link from "./Link"; @@ -14,7 +15,7 @@ const renderer = (rawStr: string): string => { return rawStr; } - const parsedContent = marked(matchResult[1], [], [Link]); + const parsedContent = marked(escape(matchResult[1]), [], [Link]); return `${parsedContent}`; }; diff --git a/web/src/labs/marked/parser/Emphasis.ts b/web/src/labs/marked/parser/Emphasis.ts index e339bf3a112c1..7dd12df1ac12e 100644 --- a/web/src/labs/marked/parser/Emphasis.ts +++ b/web/src/labs/marked/parser/Emphasis.ts @@ -1,3 +1,4 @@ +import { escape } from "lodash"; import { marked } from ".."; import Link from "./Link"; @@ -14,7 +15,7 @@ const renderer = (rawStr: string): string => { return rawStr; } - const parsedContent = marked(matchResult[1], [], [Link]); + const parsedContent = marked(escape(matchResult[1]), [], [Link]); return `${parsedContent}`; }; diff --git a/web/src/labs/marked/parser/Link.ts b/web/src/labs/marked/parser/Link.ts index 7b9ac4fc72cee..6bfc0f8a5cdce 100644 --- a/web/src/labs/marked/parser/Link.ts +++ b/web/src/labs/marked/parser/Link.ts @@ -17,7 +17,7 @@ const renderer = (rawStr: string): string => { if (!matchResult) { return rawStr; } - const parsedContent = marked(matchResult[1], [], [InlineCode, BoldEmphasis, Emphasis, Bold]); + const parsedContent = marked(escape(matchResult[1]), [], [InlineCode, BoldEmphasis, Emphasis, Bold]); return `${parsedContent}`; };