diff --git a/app/components/Highlight.tsx b/app/components/Highlight.tsx index 612c605bc..efb243714 100644 --- a/app/components/Highlight.tsx +++ b/app/components/Highlight.tsx @@ -1,3 +1,4 @@ +import { escapeRegExp } from "lodash"; import * as React from "react"; import replace from "string-replace-to-array"; import styled from "styled-components"; @@ -23,7 +24,7 @@ function Highlight({ regex = highlight; } else { regex = new RegExp( - (highlight || "").replace(/[-\\^$*+?.()|[\]{}]/g, "\\$&"), + escapeRegExp(highlight || ""), caseSensitive ? "g" : "gi" ); } diff --git a/server/queues/tasks/ImportMarkdownZipTask.ts b/server/queues/tasks/ImportMarkdownZipTask.ts index b3ce82fbe..7582ac3ad 100644 --- a/server/queues/tasks/ImportMarkdownZipTask.ts +++ b/server/queues/tasks/ImportMarkdownZipTask.ts @@ -1,4 +1,5 @@ import JSZip from "jszip"; +import { escapeRegExp } from "lodash"; import mime from "mime-types"; import { v4 as uuidv4 } from "uuid"; import documentImporter from "@server/commands/documentImporter"; @@ -160,9 +161,15 @@ export default class ImportMarkdownZipTask extends ImportTask { const reference = `<<${attachment.id}>>`; document.text = document.text - .replace(new RegExp(attachment.path, "g"), reference) - .replace(new RegExp(normalizedAttachmentPath, "g"), reference) - .replace(new RegExp(`/${normalizedAttachmentPath}`, "g"), reference); + .replace(new RegExp(escapeRegExp(attachment.path), "g"), reference) + .replace( + new RegExp(escapeRegExp(normalizedAttachmentPath), "g"), + reference + ) + .replace( + new RegExp(escapeRegExp(`/${normalizedAttachmentPath}`), "g"), + reference + ); } } diff --git a/server/queues/tasks/ImportNotionTask.ts b/server/queues/tasks/ImportNotionTask.ts index 2756d2336..be85c6b8b 100644 --- a/server/queues/tasks/ImportNotionTask.ts +++ b/server/queues/tasks/ImportNotionTask.ts @@ -1,6 +1,6 @@ import path from "path"; import JSZip from "jszip"; -import { compact } from "lodash"; +import { compact, escapeRegExp } from "lodash"; import mime from "mime-types"; import { v4 as uuidv4 } from "uuid"; import documentImporter from "@server/commands/documentImporter"; @@ -148,7 +148,7 @@ export default class ImportNotionTask extends ImportTask { ); } else { text = text.replace( - new RegExp(image.src, "g"), + new RegExp(escapeRegExp(image.src), "g"), `<<${attachment.id}>>` ); }