Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(attachments): harden reference-link rewrite regex on conversion
Elian Dorana3af8ee653fc
diff --git a/packages/trilium-core/src/becca/entities/battachment.ts b/packages/trilium-core/src/becca/entities/battachment.tsindex 17122a4da8..92d9cd0613 100644--- a/packages/trilium-core/src/becca/entities/battachment.ts+++ b/packages/trilium-core/src/becca/entities/battachment.ts@@ -10,7 +10,7 @@ import AbstractBeccaEntity from "./abstract_becca_entity.js";import type BBranch from "./bbranch.js";import type BNote from "./bnote.js";import { getSql } from "../../services/sql/index.js";-import { formatDownloadTitle, isStringNote, replaceAll } from "../../services/utils";+import { escapeRegExp, formatDownloadTitle, isStringNote, replaceAll } from "../../services/utils";const attachmentRoleToNoteTypeMapping = {image: "image",@@ -202,7 +202,7 @@ class BAttachment extends AbstractBeccaEntity<BAttachment> {// may be HTML-encoded as `&`), which we collapse to a plain note link `#root/{noteId}`.if (attachmentId) {fixedContent = fixedContent.replace(- new RegExp(`href="[^"]*attachmentId=${attachmentId}"`, "g"),+ new RegExp(`href="[^"]*attachmentId=${escapeRegExp(attachmentId)}[^"]*"`, "g"),`href="#root/${note.noteId}"`);}