An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Preserve literal document titles in labels and tooltips https://github.com/siyuan-note/siyuan/issues/19938
Danielbca9c01ca4e7
diff --git a/app/src/dialog/tooltip.ts b/app/src/dialog/tooltip.tsindex 3701b7bc9c..8ec8ed0712 100644--- a/app/src/dialog/tooltip.ts+++ b/app/src/dialog/tooltip.ts@@ -21,10 +21,12 @@ export const initTooltips = () => {const target = (event.target as Element).closest(".ariaLabel");if (target && !target.classList.contains("b3-tooltips")) {let message = target.getAttribute("aria-label") || "";- try {- message = decodeURIComponent(message);- } catch (error) {- // 保留包含不完整 URI 转义的提示文本。+ if (target.getAttribute("data-tooltip-encoding") !== "none") {+ try {+ message = decodeURIComponent(message);+ } catch (error) {+ // 保留包含不完整 URI 转义的提示文本。+ }}if (message) {showTooltip(message, target, undefined, event);diff --git a/app/src/dialog/tooltipInput.test.ts b/app/src/dialog/tooltipInput.test.tsindex 8461ccb5e8..0756029f12 100644--- a/app/src/dialog/tooltipInput.test.ts+++ b/app/src/dialog/tooltipInput.test.ts@@ -70,6 +70,16 @@ body {margin:0}.file-tree {position:absolute;top:40px;left:40px;width:232px}hover();check.equal(tip.innerHTML, "More");check.equal(tip.classList.contains("tooltip--hover"), true);+ more.setAttribute("aria-label", "A%2FB");+ hover();+ check.equal(tip.textContent, "A/B", "existing URI tooltips retain decoding");+ more.setAttribute("data-tooltip-encoding", "none");+ more.setAttribute("aria-label", "A%2FB/%3Ctag%3E.sy");+ hover();+ check.equal(tip.textContent, "A%2FB/%3Ctag%3E.sy", "document titles remain literal text");+ check.equal(tip.querySelector("tag"), null);+ more.removeAttribute("data-tooltip-encoding");+ more.setAttribute("aria-label", "More");touch();assertTouch();check.equal(getComputedStyle(tip).display, "none", "touch immediately hides an existing hover tooltip");diff --git a/app/src/layout/dock/Files.ts b/app/src/layout/dock/Files.tsindex 3a3130b049..d1b647de19 100644--- a/app/src/layout/dock/Files.ts+++ b/app/src/layout/dock/Files.ts@@ -2174,7 +2174,7 @@ class="b3-list-item b3-list-item--hide-action${actionClasses}" data-path="${item</span><span class="b3-list-item__icon${iconChanges ? " ariaLabel" : ""} popover__block${editingPublishAccess ? " fn__none" : ""}" data-position="8east" data-id="${item.id}"${iconChanges ? ` aria-label="${window.siyuan.languages.changeIcon}"` : ""}>${getFileTreeIconHTML(item.icon, defaultIcon)}</span><span class="b3-list-item__switch b3-tooltips b3-tooltips__n${editingPublishAccess ? "" : " fn__none"}" aria-label="${window.siyuan.languages.publishAccess}">${getPublishAccessOptionByLevel("public").iconHTML}</span>- <span class="b3-list-item__text ariaLabel" data-delay="200" data-position="parentE"+ <span class="b3-list-item__text ariaLabel" data-delay="200" data-position="parentE" data-tooltip-encoding="none"aria-label="${ariaLabel}">${getDocDisplayName(item.name, item.titleEmpty, true)}</span><span data-type="more-file" data-menu="true" class="b3-list-item__action b3-tooltips b3-tooltips__nw" aria-label="${window.siyuan.languages.more}"><svg><use xlink:href="#iconMore"></use></svg>diff --git a/app/src/layout/dock/PinnedDocs.tooltip.test.ts b/app/src/layout/dock/PinnedDocs.tooltip.test.tsindex 2e6290d05f..8406fd9b65 100644--- a/app/src/layout/dock/PinnedDocs.tooltip.test.ts+++ b/app/src/layout/dock/PinnedDocs.tooltip.test.ts@@ -46,7 +46,7 @@ const browserCases = async (sources: Record<string, string>) => {const ordinary = document.getElementById("ordinary");const tip = document.getElementById("tooltip");tooltip.initTooltips();- const doc = {id: "doc", notebook: "box", name: 'Title "quotes" <tag> & text', path: "/doc.sy", subFileCount: 2,+ const doc = {id: "doc", notebook: "box", name: 'A//%2F/%3Ctag%3E/Title "quotes" <tag> & text.sy', path: "/doc.sy", subFileCount: 2,hSize: "2 KB", hMtime: "2026-10-17 11:00:00", hCtime: "2026-09-01 10:00:00",bookmark: 'Mark "quoted"', name1: "Named <tag>", alias: "Alias & text", memo: "Memo <img src=x>"};for (const depth of [0, 1]) {@@ -54,6 +54,8 @@ const browserCases = async (sources: Record<string, string>) => {await panel.appendDoc(pinned, doc, "doc", depth, 0);ordinary.innerHTML = regular.render.call({element: ordinary}, doc);const title = pinned.querySelector(".b3-list-item__text");+ check.equal(title.textContent, doc.name);+ check.equal(ordinary.querySelector(".b3-list-item__text").textContent, doc.name);check.equal(title.getAttribute("aria-label"), ordinary.querySelector(".b3-list-item__text").getAttribute("aria-label"));title.dispatchEvent(new PointerEvent("pointerover", {bubbles: true, pointerType: "mouse"}));title.dispatchEvent(new MouseEvent("mouseover", {bubbles: true}));diff --git a/app/src/layout/dock/PinnedDocs.ts b/app/src/layout/dock/PinnedDocs.tsindex b9e449051d..779225708f 100644--- a/app/src/layout/dock/PinnedDocs.ts+++ b/app/src/layout/dock/PinnedDocs.ts@@ -338,7 +338,7 @@ export class PinnedDocs {const ariaLabel = doc.unavailable || !doc.hSize ? escapeAriaLabel(doc.name) +(doc.unavailable ? ` (${window.siyuan.languages.closeNotebook})` : "") : genFileTreeDocAriaLabel(doc, escapeAriaLabel);if (!doc.icon) { row.dataset.defaultIcon = doc.subFileCount ? "folder" : "file"; }- row.innerHTML = `<span data-pin-toggle="true" style="padding-left:${paddingLeft}px" class="b3-list-item__toggle b3-list-item__toggle--hl${doc.subFileCount ? "" : " fn__hidden"}"><svg class="b3-list-item__arrow"><use xlink:href="#iconRight"></use></svg></span><span class="b3-list-item__icon${iconLabel ? " ariaLabel" : ""}" data-position="8east"${iconLabel ? ` aria-label="${iconLabel}"` : ""}>${getFileTreeIconHTML(doc.icon, doc.subFileCount ? "folder" : "file")}</span><span class="b3-list-item__text ariaLabel" data-delay="200" data-position="parentE" aria-label="${ariaLabel}">${escapeHtml(doc.name)}${doc.unavailable ? ` (${window.siyuan.languages.closeNotebook})` : ""}</span><span data-pin-more="true" data-menu="true" class="b3-list-item__action" aria-label="${window.siyuan.languages.more}"><svg><use xlink:href="#iconMore"></use></svg></span>`;+ row.innerHTML = `<span data-pin-toggle="true" style="padding-left:${paddingLeft}px" class="b3-list-item__toggle b3-list-item__toggle--hl${doc.subFileCount ? "" : " fn__hidden"}"><svg class="b3-list-item__arrow"><use xlink:href="#iconRight"></use></svg></span><span class="b3-list-item__icon${iconLabel ? " ariaLabel" : ""}" data-position="8east"${iconLabel ? ` aria-label="${iconLabel}"` : ""}>${getFileTreeIconHTML(doc.icon, doc.subFileCount ? "folder" : "file")}</span><span class="b3-list-item__text ariaLabel" data-delay="200" data-position="parentE" data-tooltip-encoding="none" aria-label="${ariaLabel}">${escapeHtml(doc.name)}${doc.unavailable ? ` (${window.siyuan.languages.closeNotebook})` : ""}</span><span data-pin-more="true" data-menu="true" class="b3-list-item__action" aria-label="${window.siyuan.languages.more}"><svg><use xlink:href="#iconMore"></use></svg></span>`;if (!doc.unavailable && !window.siyuan.config.readonly) {const add = document.createElement("span");add.className = "b3-list-item__action";diff --git a/app/src/mobile/dock/MobileOutline.title.test.ts b/app/src/mobile/dock/MobileOutline.title.test.tsnew file mode 100644index 0000000000..1ce52efbb0--- /dev/null+++ b/app/src/mobile/dock/MobileOutline.title.test.ts@@ -0,0 +1,52 @@+import * as assert from "node:assert/strict";+import {readFileSync} from "node:fs";+import * as path from "node:path";+import {test} from "node:test";+import {runInNewContext} from "node:vm";+import * as ts from "typescript";+import * as escape from "../../util/escape";++const compile = (source: string) => ts.transpileModule(source, {+ compilerOptions: {module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2021},+}).outputText;+const names = {} as typeof import("../../util/pathName");+runInNewContext(compile(readFileSync("src/util/pathName.ts", "utf8")), {+ exports: names,+ window: {siyuan: {languages: {_kernel: {16: "Untitled"}}}},+ require: (id: string) => id === "path" ? path : id === "./escape" ? escape : {},+});+const source = ts.createSourceFile("MobileOutline.ts", readFileSync("src/mobile/dock/MobileOutline.ts", "utf8"),+ ts.ScriptTarget.Latest, true);+const declaration = source.statements.find(ts.isClassDeclaration);+const method = declaration.members.find(member => member.name?.getText(source) === "updateDocTitle") as ts.MethodDeclaration;+const renderer = {} as {render: (this: unknown, ial: Record<string, string>, count: number) => void};+runInNewContext(compile(`exports.render = function(ial, count) ${method.body.getText(source)};`), {+ exports: renderer,+ getDocDisplayName: names.getDocDisplayName,+ escapeHtml: escape.escapeHtml,+ getFileTreeIconHTML: () => "",+ Constants: {ZWSP: "\u200b", CUSTOM_SY_TITLE_EMPTY: "custom-sy-title-empty"},+});++test("mobile outline preserves full titles after reload and rename, including literal .sy suffixes", () => {+ let visible = false;+ const attributes = new Map<string, string>();+ const element = {+ innerHTML: "",+ classList: {add: () => visible = false, remove: () => visible = true},+ querySelector: (): null => null,+ setAttribute: (key: string, value: string) => attributes.set(key, value),+ };+ const outline = {isPreview: false, element: {querySelector: () => element}};+ for (const title of ["加密/QA19938//%2F/renamed", 'A/<tag> & "B".sy']) {+ renderer.render.call(outline, {title}, 0);+ assert.equal(attributes.get("title"), title);+ assert.equal(element.innerHTML, `<span class="b3-list-item__text">${escape.escapeHtml(title)}</span>`);+ assert.equal(visible, true);+ }+ renderer.render.call(outline, {title: "", "custom-sy-title-empty": "true"}, 0);+ assert.equal(attributes.get("title"), "Untitled");+ outline.isPreview = true;+ renderer.render.call(outline, {title: "Hidden"}, 0);+ assert.equal(visible, false);+});diff --git a/app/src/util/pathName.test.ts b/app/src/util/pathName.test.tsnew file mode 100644index 0000000000..850a5de694--- /dev/null+++ b/app/src/util/pathName.test.ts@@ -0,0 +1,37 @@+import * as assert from "node:assert/strict";+import {readFileSync} from "node:fs";+import * as path from "node:path";+import {test} from "node:test";+import {runInNewContext} from "node:vm";+import {ModuleKind, ScriptTarget, transpileModule} from "typescript";+import * as escape from "./escape";++const names = {} as typeof import("./pathName");+runInNewContext(transpileModule(readFileSync("src/util/pathName.ts", "utf8"), {+ compilerOptions: {module: ModuleKind.CommonJS, target: ScriptTarget.ES2021},+}).outputText, {+ exports: names,+ window: {siyuan: {languages: {_kernel: {16: "Untitled"}}}},+ require: (id: string) => id === "path" ? path : id === "./escape" ? escape : {},+});++test("document display names preserve complete literal titles", () => {+ for (const title of ["Plain", "A/B", "/A//B/", "A/B", "A%2FB", ".", "..", "/", "A/../B",+ "note.sy", "folder/note.sy", ".sy", "中文/😀/标题.sy", "**bold**/[link](url)", ""]) {+ assert.equal(names.getDocDisplayName(title), title, title);+ }+});++test("document display names keep empty-title placeholders and escape the entire title", () => {+ assert.equal(names.getDocDisplayName("", true), "Untitled");+ assert.equal(names.getDocDisplayName("legacy placeholder", true, true), "Untitled");+ assert.equal(names.getDocDisplayName('A/<tag> & "B".sy', false, true),+ "A/<tag> & "B".sy");+ assert.equal(names.getDocDisplayName('A/<tag> & "B".sy', false), 'A/<tag> & "B".sy');+});++test("physical file display names retain their separate basename and extension behavior", () => {+ assert.equal(names.getDisplayName("folder/note.sy", true, true), "note");+ assert.equal(names.getDisplayName("folder/note.sy", false), "folder/note.sy");+ assert.equal(names.getDisplayName("assets/image.png"), "image.png");+});diff --git a/app/src/util/pathName.ts b/app/src/util/pathName.tsindex 17179ca64f..1da25dc9a5 100644--- a/app/src/util/pathName.ts+++ b/app/src/util/pathName.ts@@ -161,11 +161,11 @@ export const getDocDisplayName = (name: string, titleEmpty?: boolean, escape?: bif (titleEmpty) {return window.siyuan.languages["_kernel"][16];}- const displayName = getDisplayName(name, true, true);+ // 文档接口返回原始标题,斜杠和 .sy 都是标题内容,不能按文件路径处理。if (escape) {- return escapeHtmlTextAndAttr(displayName);+ return escapeHtmlTextAndAttr(name);}- return displayName;+ return name;};export const getAssetPathWithoutQuery = (assetPath: string) => {@@ -789,7 +789,7 @@ const getLeaf = (liElement: HTMLElement, flashcard: boolean) => {<svg class="b3-list-item__arrow"><use xlink:href="#iconRight"></use></svg></span>${getFileTreeIconHTML(item.icon, defaultIcon, "b3-list-item__graphic", true)}- <span class="b3-list-item__text ariaLabel" data-position="parentE" aria-label="${getDocDisplayName(item.name, item.titleEmpty, true)} <small class='ft__on-surface'>${item.hSize}</small>${item.bookmark ? "<br>" + window.siyuan.languages.bookmark + " " + escapeAriaLabel(item.bookmark) : ""}${item.name1 ? "<br>" + window.siyuan.languages.name + " " + escapeAriaLabel(item.name1) : ""}${item.alias ? "<br>" + window.siyuan.languages.alias + " " + escapeAriaLabel(item.alias) : ""}${item.memo ? "<br>" + window.siyuan.languages.memo + " " + escapeAriaLabel(item.memo) : ""}${item.subFileCount !== 0 ? window.siyuan.languages.includeSubFile.replace("x", item.subFileCount) : ""}<br>${window.siyuan.languages.modifiedAt} ${item.hMtime}<br>${window.siyuan.languages.createdAt} ${item.hCtime}">${getDocDisplayName(item.name, item.titleEmpty, true)}</span>+ <span class="b3-list-item__text ariaLabel" data-position="parentE" data-tooltip-encoding="none" aria-label="${getDocDisplayName(item.name, item.titleEmpty, true)} <small class='ft__on-surface'>${item.hSize}</small>${item.bookmark ? "<br>" + window.siyuan.languages.bookmark + " " + escapeAriaLabel(item.bookmark) : ""}${item.name1 ? "<br>" + window.siyuan.languages.name + " " + escapeAriaLabel(item.name1) : ""}${item.alias ? "<br>" + window.siyuan.languages.alias + " " + escapeAriaLabel(item.alias) : ""}${item.memo ? "<br>" + window.siyuan.languages.memo + " " + escapeAriaLabel(item.memo) : ""}${item.subFileCount !== 0 ? window.siyuan.languages.includeSubFile.replace("x", item.subFileCount) : ""}<br>${window.siyuan.languages.modifiedAt} ${item.hMtime}<br>${window.siyuan.languages.createdAt} ${item.hCtime}">${getDocDisplayName(item.name, item.titleEmpty, true)}</span>${countHTML}</li>`;});