mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 07:14:33 +00:00
fix: use & instead of <> in XML escaping test for Windows NTFS compatibility (#3750)
NTFS does not allow < or > in filenames, causing the XML filename escaping test to fail on Windows CI with ENOENT. Replace file<test>.txt with file&test.txt — & is valid on all platforms and still requires XML escaping (&), preserving the test's intent. Fixes #3748
This commit is contained in:
@@ -550,10 +550,11 @@ describe("applyMediaUnderstanding", () => {
|
|||||||
it("escapes XML special characters in filenames to prevent injection", async () => {
|
it("escapes XML special characters in filenames to prevent injection", async () => {
|
||||||
const { applyMediaUnderstanding } = await loadApply();
|
const { applyMediaUnderstanding } = await loadApply();
|
||||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "moltbot-media-"));
|
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "moltbot-media-"));
|
||||||
// Create file with XML special characters in the name (what filesystem allows)
|
// Use & in filename — valid on all platforms (including Windows, which
|
||||||
|
// forbids < and > in NTFS filenames) and still requires XML escaping.
|
||||||
// Note: The sanitizeFilename in store.ts would strip most dangerous chars,
|
// Note: The sanitizeFilename in store.ts would strip most dangerous chars,
|
||||||
// but we test that even if some slip through, they get escaped in output
|
// but we test that even if some slip through, they get escaped in output
|
||||||
const filePath = path.join(dir, "file<test>.txt");
|
const filePath = path.join(dir, "file&test.txt");
|
||||||
await fs.writeFile(filePath, "safe content");
|
await fs.writeFile(filePath, "safe content");
|
||||||
|
|
||||||
const ctx: MsgContext = {
|
const ctx: MsgContext = {
|
||||||
@@ -575,10 +576,9 @@ describe("applyMediaUnderstanding", () => {
|
|||||||
|
|
||||||
expect(result.appliedFile).toBe(true);
|
expect(result.appliedFile).toBe(true);
|
||||||
// Verify XML special chars are escaped in the output
|
// Verify XML special chars are escaped in the output
|
||||||
expect(ctx.Body).toContain("<");
|
expect(ctx.Body).toContain("&");
|
||||||
expect(ctx.Body).toContain(">");
|
// The name attribute should contain the escaped form, not a raw unescaped &
|
||||||
// The raw < and > should not appear unescaped in the name attribute
|
expect(ctx.Body).toMatch(/name="file&test\.txt"/);
|
||||||
expect(ctx.Body).not.toMatch(/name="[^"]*<[^"]*"/);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("normalizes MIME types to prevent attribute injection", async () => {
|
it("normalizes MIME types to prevent attribute injection", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user