UsernameSchema, FlagSchema (#1185)

## Description:

Fix zod validation failure for flag codes that do not conform to the
SafeString pattern.

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced
- [x] I understand that submitting code with bugs that could have been
caught through manual testing blocks releases and new features for all
contributors

Co-authored-by: Scott Anderson <662325+scottanderson@users.noreply.github.com>
This commit is contained in:
Scott Anderson
2025-06-15 23:15:37 -04:00
committed by GitHub
parent fde34699eb
commit d2355b2796
+9 -6
View File
@@ -179,10 +179,13 @@ export const AttackIntentSchema = BaseIntentSchema.extend({
troops: z.number().nullable(),
});
export const UsernameSchema = SafeString;
export const FlagSchema = z.string().max(128).optional();
export const SpawnIntentSchema = BaseIntentSchema.extend({
flag: z.string().nullable(),
type: z.literal("spawn"),
name: SafeString,
name: UsernameSchema,
flag: FlagSchema,
playerType: PlayerTypeSchema,
x: z.number(),
y: z.number(),
@@ -346,8 +349,8 @@ export const ServerPrestartMessageSchema = ServerBaseMessageSchema.extend({
export const PlayerSchema = z.object({
clientID: ID,
username: SafeString,
flag: SafeString.optional(),
username: UsernameSchema,
flag: FlagSchema,
});
export const GameStartInfoSchema = z.object({
@@ -424,8 +427,8 @@ export const ClientJoinMessageSchema = z.object({
token: TokenSchema, // WARNING: PII
gameID: ID,
lastTurn: z.number(), // The last turn the client saw.
username: SafeString,
flag: SafeString.optional(),
username: UsernameSchema,
flag: FlagSchema,
});
export const ClientMessageSchema = z.discriminatedUnion("type", [