mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 01:20:12 +01:00
🐛 Fix IAL name checking functionality (#8204)
This commit is contained in:
parent
9950848a4e
commit
0d5b04e4dd
2 changed files with 9 additions and 5 deletions
|
|
@ -3,7 +3,7 @@ import {shell} from "electron";
|
||||||
/// #endif
|
/// #endif
|
||||||
import {getDockByType} from "../layout/util";
|
import {getDockByType} from "../layout/util";
|
||||||
import {confirmDialog} from "../dialog/confirmDialog";
|
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 {isLocalPath, movePathTo, moveToPath, pathPosix} from "../util/pathName";
|
||||||
import {MenuItem} from "./Menu";
|
import {MenuItem} from "./Menu";
|
||||||
import {hasClosestByClassName} from "../protyle/util/hasClosest";
|
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;
|
name = "custom-" + (item.parentElement.querySelector(".b3-text-field") as HTMLInputElement).value;
|
||||||
}
|
}
|
||||||
if (item.value.trim()) {
|
if (item.value.trim()) {
|
||||||
if (!/^custom-[_.\-0-9a-zA-Z]+$/.test(name)) {
|
if (!isValidAttrName(name)) {
|
||||||
errorTip += name.replace("custom-", "") + ", ";
|
errorTip += name.replace(/^custom-/, "") + ", ";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
attrsResult[name] = item.value;
|
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;
|
name = "custom-" + (item.parentElement.querySelector(".b3-text-field") as HTMLInputElement).value;
|
||||||
}
|
}
|
||||||
if (item.value.trim()) {
|
if (item.value.trim()) {
|
||||||
if (!/^custom-[_.\-0-9a-zA-Z]+$/.test(name)) {
|
if (!isValidAttrName(name)) {
|
||||||
errorTip += name.replace("custom-", "") + ", ";
|
errorTip += name.replace(/^custom-/, "") + ", ";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (removeAttrs.includes(name)) {
|
if (removeAttrs.includes(name)) {
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,10 @@ export const isFileAnnotation = (text: string) => {
|
||||||
return /^<<assets\/.+\/\d{14}-\w{7} ".+">>$/.test(text);
|
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
|
// REF https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/eval
|
||||||
export const looseJsonParse = (text: string) => {
|
export const looseJsonParse = (text: string) => {
|
||||||
return Function(`"use strict";return (${text})`)();
|
return Function(`"use strict";return (${text})`)();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue