Cannot start Cephalon Simaris' Synthesis because of Substring Error #381

Closed
opened 2024-06-22 19:48:03 -07:00 by VampireKitten · 3 comments
VampireKitten commented 2024-06-22 19:48:03 -07:00 (Migrated from github.com)

image

Offending code in stringHelpers.ts:

export const getJSONfromString = (str: string): any => { const jsonSubstring = str.substring(0, str.lastIndexOf("}") + 1); return JSON.parse(jsonSubstring); };

![image](https://github.com/spaceninjaserver/SpaceNinjaServer/assets/95658710/837d82c4-02f1-467f-b522-36459caa7cd9) 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: string is being violated by the caller passing in request.body instead of request.body.toString(). Why TypeScript doesn't error on this... who knows.

This code is fine, the type contract of `str: string` is being violated by the caller passing in `request.body` instead of `request.body.toString()`. Why TypeScript doesn't error on this... who knows.
OrdisPrime commented 2024-06-23 06:01:58 -07:00 (Migrated from github.com)

This code is fine, the type contract of str: string is being violated by the caller passing in request.body instead of request.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.body is the same as const someRequest = req.body as ISomeRequest

In both cases there is no type checking, as any is cast to ISomeRequest.

> This code is fine, the type contract of `str: string` is being violated by the caller passing in `request.body` instead of `request.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.body` is the same as `const someRequest = req.body as ISomeRequest` In both cases there is no type checking, as any is cast to ISomeRequest.
VampireKitten commented 2024-06-23 11:09:25 -07:00 (Migrated from github.com)

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.

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.
Sign in to join this conversation.
No description provided.