From 9840f17189db9825cc3282ad359aa57b7fb9d499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Thu, 24 Sep 2026 17:26:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E7=89=88=E6=9C=AC=E5=88=A4?= =?UTF-8?q?=E6=8D=AE=E4=B8=8D=E5=86=8D=E8=AE=A4=E4=B8=8B=E5=8E=9F=E5=9E=8B?= =?UTF-8?q?=E9=93=BE=E4=B8=8A=E7=9A=84=E9=94=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - src/components/image-editor/model3d-generation/Model3dGenerationValidation.ts:isModel3dModelVersion 改用 Object.hasOwn,`toString` / `__proto__` 这类继承键不再被判成契约版本(之后查表会拿到 undefined) - src/components/image-editor/model3d-generation/Model3dGenerationFormModel.test.ts:补原型链键回落默认版本的用例 --- .../model3d-generation/Model3dGenerationFormModel.test.ts | 6 ++++++ .../model3d-generation/Model3dGenerationValidation.ts | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/image-editor/model3d-generation/Model3dGenerationFormModel.test.ts b/src/components/image-editor/model3d-generation/Model3dGenerationFormModel.test.ts index f7cd7c859..c22199f3b 100644 --- a/src/components/image-editor/model3d-generation/Model3dGenerationFormModel.test.ts +++ b/src/components/image-editor/model3d-generation/Model3dGenerationFormModel.test.ts @@ -265,6 +265,12 @@ describe('模型版本', () => { expect(normalizeModel3dModelVersion(null)).toBe( DEFAULT_MODEL3D_MODEL_VERSION, ); + // 原型链上的键(`in` 会命中)不是契约版本,同样按默认版本处理。 + for (const inheritedKey of ['toString', 'constructor', '__proto__']) { + expect(normalizeModel3dModelVersion(inheritedKey)).toBe( + DEFAULT_MODEL3D_MODEL_VERSION, + ); + } }); it('可选项只给当前端点有底价的版本,顺序按契约声明', () => { diff --git a/src/components/image-editor/model3d-generation/Model3dGenerationValidation.ts b/src/components/image-editor/model3d-generation/Model3dGenerationValidation.ts index 303ba027d..d7f5b2c9f 100644 --- a/src/components/image-editor/model3d-generation/Model3dGenerationValidation.ts +++ b/src/components/image-editor/model3d-generation/Model3dGenerationValidation.ts @@ -53,7 +53,9 @@ export const MODEL3D_MODEL_VERSIONS = Object.keys( export function isModel3dModelVersion( value: string, ): value is Model3dModelVersion { - return value in MODEL3D_MODEL_TABLE; + // 用自有属性判断而不是 `in`:`in` 会把 `toString` / `__proto__` 这类原型链上的键也算命中, + // 之后按版本查表会拿到 undefined。 + return Object.hasOwn(MODEL3D_MODEL_TABLE, value); } export function resolveModel3dModelLabel(model: Model3dModelVersion): string {