Skip to content

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

:bug: Fix IAL name checking functionality (#8204)

颖逸0d5b04e4dd9a
diff --git a/app/src/menus/commonMenuItem.ts b/app/src/menus/commonMenuItem.ts
index f596bd9096..9ac8a8ef6e 100644
--- a/app/src/menus/commonMenuItem.ts
+++ b/app/src/menus/commonMenuItem.ts
@@ -3,7 +3,7 @@ import {shell} from "electron";
/// #endif
import {getDockByType} from "../layout/util";
import {confirmDialog} from "../dialog/confirmDialog";
-import {getSearch, isMobile} from "../util/functions";
+import {getSearch, isMobile, isValidAttrName} from "../util/functions";
import {isLocalPath, movePathTo, moveToPath, pathPosix} from "../util/pathName";
import {MenuItem} from "./Menu";
import {hasClosestByClassName} from "../protyle/util/hasClosest";
@@ -310,8 +310,8 @@ export const openFileAttr = (attrs: IObject, id: string, focusName = "bookmark")
name = "custom-" + (item.parentElement.querySelector(".b3-text-field") as HTMLInputElement).value;
}
if (item.value.trim()) {
- if (!/^custom-[_.\-0-9a-zA-Z]+$/.test(name)) {
- errorTip += name.replace("custom-", "") + ", ";
+ if (!isValidAttrName(name)) {
+ errorTip += name.replace(/^custom-/, "") + ", ";
return;
}
attrsResult[name] = item.value;
@@ -381,8 +381,8 @@ export const openAttr = (nodeElement: Element, protyle: IProtyle, focusName = "b
name = "custom-" + (item.parentElement.querySelector(".b3-text-field") as HTMLInputElement).value;
}
if (item.value.trim()) {
- if (!/^custom-[_.\-0-9a-zA-Z]+$/.test(name)) {
- errorTip += name.replace("custom-", "") + ", ";
+ if (!isValidAttrName(name)) {
+ errorTip += name.replace(/^custom-/, "") + ", ";
return;
}
if (removeAttrs.includes(name)) {
diff --git a/app/src/util/functions.ts b/app/src/util/functions.ts
index 3e5c6a4408..8ce19efa46 100644
--- a/app/src/util/functions.ts
+++ b/app/src/util/functions.ts
@@ -42,6 +42,10 @@ export const isFileAnnotation = (text: string) => {
return /^<<assets\/.+\/\d{14}-\w{7} ".+">>$/.test(text);
};
+export const isValidAttrName = (name: string) => {
+ return /^[_a-zA-Z][_.\-0-9a-zA-Z]*$/.test(name);
+};
+
// REF https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/eval
export const looseJsonParse = (text: string) => {
return Function(`"use strict";return (${text})`)();