The toBool helper function can lead to unexpected behavior. Any string value for an environment variable that is not '1', 'true', or 'yes' (case-insensitive) will be evaluated as false by the current implementation. For example, if a user makes a typo like PREFUND_ENABLED=ture, it will be interpreted as false without any warning, which could be surprising. A more robust implementation would explicitly handle both truthy and falsy values, and treat any other unrecognized string as an invalid input (by returning undefined), letting zod handle defaults or throw an error.
const toBool = (value?: string) => value !== undefined ? ([_x22_1_x22_, _x22_true_x22_, _x22_yes_x22_].includes(value.toLowerCase()) ? true : [_x22_0_x22_, _x22_false_x22_, _x22_no_x22_].includes(value.toLowerCase()) ? false : undefined) : undefined
Originally posted by @gemini-code-assist[bot] in #2493 (comment)
The
toBoolhelper function can lead to unexpected behavior. Any string value for an environment variable that is not '1', 'true', or 'yes' (case-insensitive) will be evaluated asfalseby the current implementation. For example, if a user makes a typo likePREFUND_ENABLED=ture, it will be interpreted asfalsewithout any warning, which could be surprising. A more robust implementation would explicitly handle both truthy and falsy values, and treat any other unrecognized string as an invalid input (by returningundefined), lettingzodhandle defaults or throw an error.Originally posted by @gemini-code-assist[bot] in #2493 (comment)