lab.js icon indicating copy to clipboard operation
lab.js copied to clipboard

bug - study/open : on wrong format

Open rbalet opened this issue 4 years ago • 2 comments

This issue isn't that bad, but if somebody have the time to fix it :)

What is currently happening?

On opening a project that doesn't have the right format (ex, an array withing a json) the website just start an infinite Loop
image

Please describe the steps needed to reproduce this phenomenon

  1. save the json
  2. surround it with []
  3. open this file within the app

Finally, please tell us which browser you're using (and the version thereof)

Chrome - V76.0.3809.100

rbalet avatar Aug 22 '19 13:08 rbalet

Hej @rbalet, thanks a lot, this is an excellent observation! Indeed, we trust the input too much, and very likely it would be worth checking if the underlying code can deal with malformed input, too (e.g. the components key being an array).

What do you think a good solution would look like -- would you validate the the project is an object (as opposed to an array)? Would you do something like a more complex schema-based validation to check the structure of the object in detail?

FelixHenninger avatar Aug 26 '19 19:08 FelixHenninger

would you validate the the project is an object (as opposed to an array)? : I've done that in the pull request.

could you do something like a more complex schema-based validation to check the structure of the object in detail? : it's already working pretty well. (You do a check on the object, so if it's not the right element, it will just don't work.

I don't know if this is a good practice. But we could instantiate the object within the constructor of a class instead of using an interface. So, we passing trough the object an becoming a right formatted element. (Even if we had a bug somewhere). And the unknown element would just be ignored.

Here an example

export class Category {
  id: string
  title?: string
  iconId?: string
  color?: string

  constructor(item) {
    {
      this.id = item.id || null
      this.title = item.title || ''
      this.iconId = item.iconId || ''
      this.color = item.color || ''
    }
  }
}

rbalet avatar Aug 27 '19 07:08 rbalet