Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Escape block name, alias and memo in reference hint

Danielf0dbe37f2637
diff --git a/app/src/protyle/hint/extend.ts b/app/src/protyle/hint/extend.ts
index 0ec006039a..7895bdc349 100644
--- a/app/src/protyle/hint/extend.ts
+++ b/app/src/protyle/hint/extend.ts
@@ -449,13 +449,13 @@ export const genHintItemHTML = (item: IBlock) => {
}
let attrHTML = "";
if (item.name) {
- attrHTML += `<span class="fn__flex"><svg class="b3-list-item__hinticon"><use xlink:href="#iconN"></use></svg><span>${item.name}</span></span><span class="fn__space"></span>`;
+ attrHTML += `<span class="fn__flex"><svg class="b3-list-item__hinticon"><use xlink:href="#iconN"></use></svg><span>${escapeHtml(item.name)}</span></span><span class="fn__space"></span>`;
}
if (item.alias) {
- attrHTML += `<span class="fn__flex"><svg class="b3-list-item__hinticon"><use xlink:href="#iconA"></use></svg><span>${item.alias}</span></span><span class="fn__space"></span>`;
+ attrHTML += `<span class="fn__flex"><svg class="b3-list-item__hinticon"><use xlink:href="#iconA"></use></svg><span>${escapeHtml(item.alias)}</span></span><span class="fn__space"></span>`;
}
if (item.memo) {
- attrHTML += `<span class="fn__flex"><svg class="b3-list-item__hinticon"><use xlink:href="#iconM"></use></svg><span>${item.memo}</span></span>`;
+ attrHTML += `<span class="fn__flex"><svg class="b3-list-item__hinticon"><use xlink:href="#iconM"></use></svg><span>${escapeHtml(item.memo)}</span></span>`;
}
if (attrHTML) {
attrHTML = `<div class="fn__flex b3-list-item__meta b3-list-item__showall">${attrHTML}</div>`;
@@ -520,11 +520,12 @@ export const hintRef = (key: string, protyle: IProtyle, source: THintSource): IH
createItemCount++;
}
response.data.blocks.forEach((item: IBlock) => {
- let value = `<span data-type="block-ref" data-id="${item.id}" data-subtype="d">${item.name || item.refText.replace(new RegExp(Constants.ZWSP, "g"), "")}</span>`;
+ const name = item.name ? escapeHtml(item.name) : item.refText.replace(new RegExp(Constants.ZWSP, "g"), "");
+ let value = `<span data-type="block-ref" data-id="${item.id}" data-subtype="d">${name}</span>`;
if (source === "search") {
- value = `<span data-type="block-ref" data-id="${item.id}" data-subtype="s">${key}${Constants.ZWSP}${item.name || item.refText.replace(new RegExp(Constants.ZWSP, "g"), "")}</span>`;
+ value = `<span data-type="block-ref" data-id="${item.id}" data-subtype="s">${key}${Constants.ZWSP}${name}</span>`;
} else if (source === "av") {
- let refText = item.name || item.refText.replace(new RegExp(Constants.ZWSP, "g"), "");
+ let refText = name;
if (nodeElement) {
refText = item.ial["custom-sy-av-s-text-" + nodeElement.getAttribute("data-av-id")] || refText;
}
diff --git a/app/src/protyle/hint/index.ts b/app/src/protyle/hint/index.ts
index 44f96b67b5..6ebfdac028 100644
--- a/app/src/protyle/hint/index.ts
+++ b/app/src/protyle/hint/index.ts
@@ -33,6 +33,7 @@ import {highlightRender} from "../render/highlightRender";
import {assetMenu, imgMenu} from "../../menus/protyle";
import {hideElements} from "../ui/hideElements";
import {fetchPost} from "../../util/fetch";
+import {escapeHtml} from "../../util/escape";
import {getDisplayName, isEncryptedBox, pathPosix} from "../../util/pathName";
import {
addEmoji,
@@ -468,7 +469,7 @@ export class Hint {
let blockRefHTML;
if (source === "av") {
// av 搜索时需要获取值 https://github.com/siyuan-note/siyuan/issues/12020
- let refText = item.name || item.refText.replace(new RegExp(Constants.ZWSP, "g"), "");
+ let refText = item.name ? escapeHtml(item.name) : item.refText.replace(new RegExp(Constants.ZWSP, "g"), "");
if (nodeElement) {
refText = item.ial["custom-sy-av-s-text-" + nodeElement.getAttribute("data-av-id")] || refText;
}