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 <noreply@anthropic.com>
这个提交存在于:
父节点
785f125efc
当前提交
28ec3001ac
共有 2 个文件被更改,包括 38 次插入 和 1 次删除
37
src/features/pet/types.test.ts
普通文件
37
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();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -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),
|
||||
|
|
|
|||
正在加载…
添加表格
在新工单中引用