Skip to content

World's first open-source enterprise world model.

Leave unfinished numeric rule conditions unset instead of saving zero (#1148)

Rudy Mizrahi Celekli99d6468c3c4f
diff --git a/web/src/pages/RulesPanel.tsx b/web/src/pages/RulesPanel.tsx
index 0ecccca3..7ec9b070 100644
--- a/web/src/pages/RulesPanel.tsx
+++ b/web/src/pages/RulesPanel.tsx
@@ -94,10 +94,11 @@ function operandText(op: string, operand: unknown, attributes: RelationTypeView[
}
/** 输入框文本 → 操作数。**解析不出来就返回 undefined**,由调用方拦在保存之前 */
-function parseOperand(op: string, text: string): unknown | undefined {
+export function parseOperand(op: string, text: string): unknown | undefined {
const kind = operandKind(op);
if (kind === "none") return undefined;
const t = text.trim();
+ if (!t) return undefined;
if (kind === "set") {
const set = t
.split(",")
diff --git a/web/src/pages/ruleEmptyOperands.test.ts b/web/src/pages/ruleEmptyOperands.test.ts
new file mode 100644
index 00000000..bf0c1e8d
--- /dev/null
+++ b/web/src/pages/ruleEmptyOperands.test.ts
@@ -0,0 +1,12 @@
+import { describe, expect, it } from "vitest";
+import { parseOperand } from "./RulesPanel";
+
+describe("unfinished numeric rule conditions", () => {
+ it.each(["gt", "gte", "lt", "lte"])("does not turn an empty %s operand into zero", (op) => {
+ expect(parseOperand(op, "")).toBeUndefined();
+ expect(parseOperand(op, " ")).toBeUndefined();
+ });
+ it("still accepts a deliberately written zero", () => {
+ expect(parseOperand("gt", "0")).toBe(0);
+ });
+});