模型版本判据不再认下原型链上的键

- src/components/image-editor/model3d-generation/Model3dGenerationValidation.ts:isModel3dModelVersion 改用 Object.hasOwn,`toString` / `__proto__` 这类继承键不再被判成契约版本(之后查表会拿到 undefined)
- src/components/image-editor/model3d-generation/Model3dGenerationFormModel.test.ts:补原型链键回落默认版本的用例
This commit is contained in:
2026-09-24 17:26:49 +08:00
parent 3191ca9d89
commit 9840f17189
2 changed files with 9 additions and 1 deletions
@@ -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('可选项只给当前端点有底价的版本,顺序按契约声明', () => {
@@ -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 {