Cannot start Cephalon Simaris' Synthesis because of Substring Error #381
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Offending code in stringHelpers.ts:
export const getJSONfromString = (str: string): any => { const jsonSubstring = str.substring(0, str.lastIndexOf("}") + 1); return JSON.parse(jsonSubstring); };This code is fine, the type contract of
str: stringis being violated by the caller passing inrequest.bodyinstead ofrequest.body.toString(). Why TypeScript doesn't error on this... who knows.body is any since it can be anything. Incoming data should be validated, usually. However, in the case of SNS, we rely on the assumption that the client provides correct data. A few requests are validated with manual validation functions. This is cumbersome though. It's possible to add a validation library that validates incoming data based on ts types/interfaces. However, this is not priority.
any can be assigned to every type, and vice versa, any means disabling type checking, that's why ts doesn't error.
In the case of the getJSONFromString function, req.body's any can be passed to string.
Also for code like:
const someRequest: ISomeRequest = req.bodyis the same asconst someRequest = req.body as ISomeRequestIn both cases there is no type checking, as any is cast to ISomeRequest.
While the new PR does fix the issue of not being able to finish dialogue with Simaris, it appears it's not saved to the Database, as completing the tutorial for Synthesis immediately brought back the initial dialogue. As well, it still doesn't give you the Starter Pack it's meant to give you.