-
Notifications
You must be signed in to change notification settings - Fork 270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CODEBASE: Recheck all usages of typecasting with JSON.parse #1775
base: dev
Are you sure you want to change the base?
CODEBASE: Recheck all usages of typecasting with JSON.parse #1775
Conversation
In the latest commit, I refactored
Rationale:
From now on, I'll use this code for other "loader" functions if I need to change them (I'm testing another PR that changes let somethingData: unknown;
try {
somethingData = JSON.parse(saveString, Reviver);
} catch (error) {
console.error(error);
}
if (!validate(somethingData)) {
console.error("Invalid somethingData:", saveString);
somethingData = DefaultData;
setTimeout(() => {
dialogBoxCreate("Cannot load data of something. Something is reset.");
}, 1000);
return;
}
something = somethingData; After #1774 is merged, with proper "loader" functions, we can gradually deal with legacy code in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: Have to test this on the old saves too
Unrelated question: |
While we search and fix lint errors, we (kind of) agree that we should not typecast the result of
JSON.parse
(e.g.,JSON.parse(saveString, Reviver) as Something
. This PR searches all references ofJSON.parse
and checks if they are typecasting in a questionable way. My guideline:unknown
.