farirpgs / fari-app

The Free and Open-Source VTT
https://fari.app/
GNU Affero General Public License v3.0
291 stars 59 forks source link

Import of malformed character sheet .json possible #536

Open maxschlosser opened 8 months ago

maxschlosser commented 8 months ago

🚩 Describe the bug

It is possible to import character JSON that is missing the id field for at least one element. The same applies to duplicate ids.

I already talked to @lynn0702 on Discord, who told me that missing or duplicate id will very likely lead to a broken UI and internal failures.

🔢 Steps to reproduce

  1. Create a new character
  2. Import a template (e.g. Savage Worlds)
  3. Set a value
  4. Export the character to a JSON (sheet.json)
  5. Delete the character
  6. Edit sheet.json, either .. remove the id field of some elements .. edit two id fields to be the same
  7. Create a new character
  8. Import the modified sheet.json
  9. Export the imported character

Note: Steps 2 and 3 might not be necessary, but that is what I did.

🟢 Expected behavior

I would expect one of two behaviors if ids are missing or duplicate:

  1. The JSON is rejected with an error. An output on which field(s) caused the issue would be very useful but may not be feasible.
  2. The JSON is repaired with new unique ids.

🔴 Actual behavior

Fari accepts the import and generates what looks like a correctly formatted character sheet. The ids are still missing or malformed when the sheet is exported again.

💅 Screenshots

...

🖥 Desktop or Smartphone

📄 Additional context

Malformed Input:

maxschlosser commented 8 months ago

If you can give me some pointers on where to start I could check if I can fix this myself. Looking for import surprisingly didn't turn up anything useful 😅