lab.js
lab.js copied to clipboard
bug - study/open : on wrong format
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
Please describe the steps needed to reproduce this phenomenon
- save the json
- surround it with
[]
- open this file within the app
Finally, please tell us which browser you're using (and the version thereof)
Chrome - V76.0.3809.100
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?
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 || ''
}
}
}