fix(datalink): preserve quoted literal types and text identifiers

This commit is contained in:
gitea committed 2026-10-20 18:01:57 +08:00
1 parent fac81b08e8
commit 6451c120f0
4 files changed
+185 -172

No files matched your search

+2
View File
@@ -86,3 +86,5 @@ for await (const rawRecord of iterateAllEntityRecords(runtime.clients.ekbClient,
}
```
`--set` 中带单引号或双引号的值明确表示字符串,并解码字符串转义;例如 `编码="001"` 保留前导零,`名称="true"` 保留文本。未加引号的数值、`true/false/null` 继续按对应类型转换。
+6 -5
View File
@@ -1278,16 +1278,17 @@ export function parseSetClause(
const rawKey = assign.slice(0, eqIdx).trim();
let rawVal = assign.slice(eqIdx + 1).trim();
// 去除外层引号
if ((rawVal.startsWith('"') && rawVal.endsWith('"')) || (rawVal.startsWith("'") && rawVal.endsWith("'"))) {
rawVal = rawVal.slice(1, -1);
}
// 去除外层引号,同时保留显式字符串的类型与转义语义。
const quoted = (rawVal.startsWith('"') && rawVal.endsWith('"')) || (rawVal.startsWith("'") && rawVal.endsWith("'"));
const literal = quoted ? predicateLiteral(rawVal) : undefined;
const field = resolveEntityField(entity, rawKey);
const targetKey = field ? field.name : rawKey;
// 类型智能转换
if (rawVal === "true") {
if (quoted) {
result[targetKey] = literal;
} else if (rawVal === "true") {
result[targetKey] = true;
} else if (rawVal === "false") {
result[targetKey] = false;
+10
View File
@@ -0,0 +1,10 @@
import { expect, test } from "bun:test";
import { parseSetClause } from "./services.js";
const entity = { id: "entity", fields: [{ name: "code", label: "编码", type: "text" }, { name: "name", label: "名称", type: "text" }] } as any;
test("quoted numbers, booleans and null remain text while bare literals retain conversion", () => {
expect(parseSetClause('编码="001", 名称="true"', entity)).toEqual({ code: "001", name: "true" });
expect(parseSetClause("编码='false', 名称='null'", entity)).toEqual({ code: "false", name: "null" });
expect(parseSetClause("code=42, name=false", entity)).toEqual({ code: 42, name: false });
expect(parseSetClause("code=null", entity)).toEqual({ code: null });
expect(parseSetClause(String.raw`code="A\"B"`, entity)).toEqual({ code: 'A"B' });
});