Skip to content

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

:bug: Preserve shared imports across frontend build targets https://github.com/siyuan-note/siyuan/issues/20055

Daniele30e014b157a
diff --git a/app/src/config/tabs/appTab.test.ts b/app/src/config/tabs/appTab.test.ts
index f3558a8324..928f1d39c6 100644
--- a/app/src/config/tabs/appTab.test.ts
+++ b/app/src/config/tabs/appTab.test.ts
@@ -4,6 +4,7 @@ import {resolve} from "node:path";
import {test} from "node:test";
import {runInNewContext} from "node:vm";
import {ModuleKind, transpileModule} from "typescript";
+import {escapeHtmlTextAndAttr} from "../../util/escape";
const {parse} = require("ifdef-loader/preprocessor");
@@ -23,7 +24,7 @@ const getAccessibilitySlot = (browser: boolean, mobile: boolean, invoke?: Invoke
console: {warn: (): void => undefined},
window: {siyuan: {
languages: new Proxy({}, {get: (_, key) => String(key)}),
- config: {system: {isMicrosoftStore: true}},
+ config: {system: {isMicrosoftStore: true, networkProxy: {host: 'user:"<&@host', port: "7890", scheme: "http"}}},
}},
require: (name: string) => {
if (name === "electron") {
@@ -36,6 +37,9 @@ const getAccessibilitySlot = (browser: boolean, mobile: boolean, invoke?: Invoke
if (name === "../../util/hostCapabilities") {
return {getHostCapabilities: () => ({importExport: false, workspaces: false})};
}
+ if (name === "../../util/escape") {
+ return {escapeHtmlTextAndAttr};
+ }
return new Proxy({}, {get: () => () => ""});
},
});
@@ -67,6 +71,15 @@ test("settings window mode is configurable only in the Electron desktop client",
}
});
+test("network proxy renders escaped values in every build target", () => {
+ for (const [browser, mobile] of [[false, false], [true, false], [true, true], [false, true]]) {
+ const slot = getAccessibilitySlot(browser, mobile, undefined, "networkProxy");
+ assert.ok(slot);
+ assert.ok(slot.html().includes('value="user:&quot;&lt;&amp;@host"'));
+ assert.ok(slot.html().includes('value="7890"'));
+ }
+});
+
const controls = () => {
let change: () => Promise<void>;
const input = {
diff --git a/app/src/config/tabs/appTab.ts b/app/src/config/tabs/appTab.ts
index bfaba73e86..d15946e808 100644
--- a/app/src/config/tabs/appTab.ts
+++ b/app/src/config/tabs/appTab.ts
@@ -16,13 +16,14 @@ import {exportLayout} from "../../layout/util";
import {exitSiYuan} from "../../dialog/processSystem";
import {showMessage} from "../../dialog/message";
import {isMac, saveExportFile} from "../../protyle/util/compatibility";
+import {escapeHtmlTextAndAttr} from "../../util/escape";
/// #if MOBILE
import {confirmDialog} from "../../dialog/confirmDialog";
import {Dialog} from "../../dialog";
import {openInputDialog} from "../../dialog/inputDialog";
import {isInMobileApp} from "../../protyle/util/compatibility";
import {pathPosix} from "../../util/pathName";
-import {escapeHtmlTextAndAttr, escapeAttr, escapeHtml} from "../../util/escape";
+import {escapeAttr, escapeHtml} from "../../util/escape";
/// #endif
/// #if !BROWSER
import {afterExport} from "../../protyle/export/util";
diff --git a/app/src/protyle/index.ts b/app/src/protyle/index.ts
index 1ac2de19d6..0d56b1e5ed 100644
--- a/app/src/protyle/index.ts
+++ b/app/src/protyle/index.ts
@@ -59,8 +59,8 @@ import {
refreshSearchPathAfterRename,
} from "../search/path";
import {syncSearchConfigHPath} from "../search/config";
-import {sanitizeKernelHTML} from "../util/hostCapabilities";
/// #endif
+import {sanitizeKernelHTML} from "../util/hostCapabilities";
import {isSupportCSSHL} from "./render/searchMarkRender";
import {renderAVAttribute} from "./render/av/blockAttr";
import {setFoldById, zoomOut} from "../menus/protyle";
diff --git a/app/tests/conditionalImports.test.js b/app/tests/conditionalImports.test.js
new file mode 100644
index 0000000000..273536bbdb
--- /dev/null
+++ b/app/tests/conditionalImports.test.js
@@ -0,0 +1,21 @@
+const assert = require("node:assert/strict");
+const {readFileSync} = require("node:fs");
+const path = require("node:path");
+const {test} = require("node:test");
+const ts = require("typescript");
+const {parse} = require("ifdef-loader/preprocessor");
+
+test("shared editor sanitization remains bound after conditional preprocessing", () => {
+ const source = readFileSync(path.join(__dirname, "../src/protyle/index.ts"), "utf8");
+ for (const BROWSER of [false, true]) {
+ for (const MOBILE of [false, true]) {
+ const processed = parse(source, {BROWSER, MOBILE}, false, true);
+ const file = ts.createSourceFile("index.ts", processed, ts.ScriptTarget.Latest, true);
+ const imports = file.statements.filter(ts.isImportDeclaration);
+ assert.ok(imports.some(statement =>
+ statement.moduleSpecifier.text === "../util/hostCapabilities" &&
+ statement.importClause?.namedBindings?.elements?.some(binding =>
+ binding.name.text === "sanitizeKernelHTML")), `BROWSER=${BROWSER}, MOBILE=${MOBILE}`);
+ }
+ }
+});