fix: strip trailing punctuation from MEDIA tokens and add tests

This commit is contained in:
Peter Steinberger
2025-11-25 06:07:11 +01:00
parent 9fbeb2ccd3
commit ad55832cda
2 changed files with 35 additions and 4 deletions

View File

@@ -223,6 +223,31 @@ describe("config and templating", () => {
expect(result?.mediaUrl).toBe("/tmp/pic.png");
});
it("captures MEDIA token with trailing JSON characters", async () => {
const runSpy = vi.spyOn(index, "runCommandWithTimeout").mockResolvedValue({
stdout: 'MEDIA:/tmp/pic.png"} trailing',
stderr: "",
code: 0,
signal: null,
killed: false,
});
const cfg = {
inbound: {
reply: {
mode: "command" as const,
command: ["echo", "{{Body}}"],
},
},
};
const result = await index.getReplyFromConfig(
{ Body: "hi", From: "+1", To: "+2" },
undefined,
cfg,
runSpy,
);
expect(result?.mediaUrl).toBe("/tmp/pic.png");
});
it("ignores invalid MEDIA lines with whitespace", async () => {
const runSpy = vi.spyOn(index, "runCommandWithTimeout").mockResolvedValue({
stdout: "hello\nMEDIA: not a url with spaces\nrest\n",