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 {