From 28ec3001ac7e54d169b649bdb9ae415171ec74e3 Mon Sep 17 00:00:00 2001 From: YokiiroBW Date: Sun, 26 Jul 2026 22:28:34 +0800 Subject: [PATCH] fix(pet): correct manifest image pattern The manifest filename pattern used `\.` inside a regex literal, which matches a literal backslash followed by any character, while the surrounding character class already excludes backslashes. Every valid pack was rejected, including the one bundled in this repository, so pack import was entirely unusable. Adds a test that parses the bundled manifest so the pattern cannot regress. Refs P1-12 / F-02. Co-Authored-By: Claude Opus 5 --- src/features/pet/types.test.ts | 37 ++++++++++++++++++++++++++++++++++ src/features/pet/types.ts | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/features/pet/types.test.ts diff --git a/src/features/pet/types.test.ts b/src/features/pet/types.test.ts new file mode 100644 index 0000000..57ddb2d --- /dev/null +++ b/src/features/pet/types.test.ts @@ -0,0 +1,37 @@ +import { describe, expect, it } from "vitest"; + +import aemeathManifest from "./assets/aemeath/manifest.json"; +import { petPackManifestSchema } from "./types"; + +describe("pet pack manifest schema", () => { + // Regression: the image pattern used `\\.` instead of `\.`, which required a + // literal backslash in the file name and therefore rejected every valid pack, + // including the one shipped in this repository. + it("accepts the bundled aemeath manifest", () => { + expect(petPackManifestSchema.parse(aemeathManifest).image).toBe( + "aemeath-spritesheet.png", + ); + }); + + it("accepts plain png and webp file names", () => { + for (const image of ["pet.png", "pet.webp", "my-pet_v2.PNG"]) { + expect( + petPackManifestSchema.parse({ ...aemeathManifest, image }).image, + ).toBe(image); + } + }); + + it("rejects path traversal and unsupported extensions", () => { + for (const image of [ + "../escape.png", + "nested/pet.png", + "C:\\pet.png", + "pet.gif", + "pet.png.exe", + ]) { + expect(() => + petPackManifestSchema.parse({ ...aemeathManifest, image }), + ).toThrow(); + } + }); +}); diff --git a/src/features/pet/types.ts b/src/features/pet/types.ts index 92dbe01..4f0d6a8 100644 --- a/src/features/pet/types.ts +++ b/src/features/pet/types.ts @@ -44,7 +44,7 @@ export const petPackManifestSchema = z format: z.literal("astrbot-pet-pack.v1"), name: z.string().min(1).max(80), version: z.string().min(1).max(32), - image: z.string().regex(/^[^\\/:*?"<>|]+\\.(png|webp)$/i), + image: z.string().regex(/^[^\\/:*?"<>|]+\.(png|webp)$/i), width: z.number().int().positive().max(4096), height: z.number().int().positive().max(4096), frameWidth: z.number().int().positive().max(1024),