Skip to content

Conversation

@AkaHarshit
Copy link

Pasting arbitrary JSON previously created broken “note” entities because the clipboard importer treated every validation result as truthy. That produced orphaned notes, NaN positions, and cascading save/export failures. This change adds a shared payload classifier so only valid tables/areas/notes are recreated.

Steps to Reproduce
•Copy { "foo": "bar" }.
•Focus the editor canvas and press Ctrl/Cmd+V.
•Observe a blank note with bad coordinates; subsequent saves or exports often error.

Root Cause
ControlPanel.paste() called validator.validate(obj, noteSchema) and used the returned object directly in the if condition. Because the result object is always truthy, the “note” branch ran for any JSON payload, regardless of validity.

Fix
•Introduced classifyClipboardPayload() in src/utils/clipboard.js that checks tables, areas, and notes against their jsonschema definitions and returns null when no schema matches.
•Updated ControlPanel.paste() to consume the classifier and keep the existing offset/id behavior only when the payload is valid. Invalid data is now ignored safely.
•Added tests/clipboard.test.js using Node’s native test runner plus an npm run test script to prevent regressions.

Before / After
•Before: Any JSON blob (or even plain text that parses) spawned a corrupt note.
•After: Only valid tables/areas/notes are pasted; other payloads are ignored without breaking the diagram.

Breaking Changes
None.

Tests
•npm run test (covers the new clipboard classifier)

Checklist
[x] Code formatted and linted locally (run npm run lint after npm install)
[x] Tests added/updated (tests/clipboard.test.js)
[x] Build verified (npm run build pending local install)
[x] No strings or locales changed
[x] No unrelated refactors

@vercel
Copy link

vercel bot commented Nov 19, 2025

@AkaHarshit is attempting to deploy a commit to the dottle's projects Team on Vercel.

A member of the Team first needs to authorize it.

@AkaHarshit AkaHarshit closed this Nov 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant