AI-native design editor. Open-source Figma alternative.
fix(editor): guard setOpacity against non-finite values
sadkodevd1284cd01ba9
diff --git a/packages/core/src/editor/nodes.ts b/packages/core/src/editor/nodes.tsindex f563ba5c5..f5fcb3337 100644--- a/packages/core/src/editor/nodes.ts+++ b/packages/core/src/editor/nodes.ts@@ -11,7 +11,7 @@ import { createVariableBindingActions } from './variable-bindings'export function opacityFromBuffer(buffer: string): number {if (buffer === '0') return 1const n = Number.parseInt(buffer, 10)- if (Number.isNaN(n)) return 1+ if (!Number.isFinite(n)) return 1const percent = buffer.length === 1 ? n * 10 : nreturn Math.min(100, Math.max(0, percent)) / 100}@@ -60,6 +60,7 @@ export function createNodeActions(ctx: EditorContext) {}function setOpacity(opacity: number) {+ if (!Number.isFinite(opacity)) returnconst clamped = Math.max(0, Math.min(1, opacity))const ids = [...ctx.state.selectedIds]if (ids.length === 0) returndiff --git a/tests/engine/editor/opacity.test.ts b/tests/engine/editor/opacity.test.tsindex a4b346e63..5e8e3de8b 100644--- a/tests/engine/editor/opacity.test.ts+++ b/tests/engine/editor/opacity.test.ts@@ -97,6 +97,30 @@ describe('editor.setOpacity', () => {editor.setOpacity(0.5)expect(editor.undo.canUndo).toBe(false)})++ test('rejects NaN', () => {+ const { editor, rect } = setup()++ editor.setOpacity(Number.NaN)+ expect(getNodeOrThrow(editor.graph, rect.id).opacity).toBe(1)+ expect(editor.undo.canUndo).toBe(false)+ })++ test('rejects Infinity', () => {+ const { editor, rect } = setup()++ editor.setOpacity(Number.POSITIVE_INFINITY)+ expect(getNodeOrThrow(editor.graph, rect.id).opacity).toBe(1)+ expect(editor.undo.canUndo).toBe(false)+ })++ test('rejects -Infinity', () => {+ const { editor, rect } = setup()++ editor.setOpacity(Number.NEGATIVE_INFINITY)+ expect(getNodeOrThrow(editor.graph, rect.id).opacity).toBe(1)+ expect(editor.undo.canUndo).toBe(false)+ })})describe('opacityFromBuffer', () => {