nusmodifications / nusmods

🏫 Official course planning platform for National University of Singapore.
https://nusmods.com
MIT License
557 stars 270 forks source link

Add well-formed timetable validation check #3673

Closed kokrui closed 2 months ago

kokrui commented 3 months ago

Right now, NUSMods just checks on load for whether a timetable object exists. This could potentially cause issues since we never explicitly check that data is of type PageData. Notice here that data is implicitly converted from any as returned in JSON.parse to PageData, received as a parameter to validatePageData.

https://github.com/nusmodifications/nusmods/blob/47238fa8203fb0b6432b74a9d737e7fc4314b4ae/export/src/data.ts#L49-L50

https://github.com/nusmodifications/nusmods/blob/089993f56557c729572284b762384424f7806d53/export/src/data.ts#L66-L71

We could implement a basic check that the data it contains is well-formed according to PageData's type definition.