nusmodifications/nusmods

Add well-formed timetable validation check

Closed this issue · 0 comments

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.

const data = JSON.parse(ctx.query.data);
validateExportData(data);

// TODO: Improve these validation
if (!_.isObject(data.timetable)) {
throw new Error('Invalid timetable');
}

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