fix: anchor MEDIA tag parsing
This commit is contained in:
@@ -34,4 +34,17 @@ describe("splitMediaFromOutput", () => {
|
||||
expect(first.audioAsVoice).toBe(true);
|
||||
expect(second.audioAsVoice).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps MEDIA mentions in prose", () => {
|
||||
const input = "The MEDIA: tag fails to deliver";
|
||||
const result = splitMediaFromOutput(input);
|
||||
expect(result.mediaUrls).toBeUndefined();
|
||||
expect(result.text).toBe(input);
|
||||
});
|
||||
|
||||
it("parses MEDIA tags with leading whitespace", () => {
|
||||
const result = splitMediaFromOutput(" MEDIA:/tmp/screenshot.png");
|
||||
expect(result.mediaUrls).toEqual(["/tmp/screenshot.png"]);
|
||||
expect(result.text).toBe("");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -71,6 +71,13 @@ export function splitMediaFromOutput(raw: string): {
|
||||
continue;
|
||||
}
|
||||
|
||||
const trimmedStart = line.trimStart();
|
||||
if (!trimmedStart.startsWith("MEDIA:")) {
|
||||
keptLines.push(line);
|
||||
lineOffset += line.length + 1; // +1 for newline
|
||||
continue;
|
||||
}
|
||||
|
||||
const matches = Array.from(line.matchAll(MEDIA_TOKEN_RE));
|
||||
if (matches.length === 0) {
|
||||
keptLines.push(line);
|
||||
|
||||
Reference in New Issue
Block a user