fix(agents): defuse unicode-whitespace MEDIA lines · openclaw/openclaw@0020a32
zqchris
·
2026-04-23
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -81,6 +81,23 @@ describe("createTtsTool", () => {
|
81 | 81 | expect(rendered).toContain("[\u2060[audio_as_voice]]"); |
82 | 82 | }); |
83 | 83 | |
| 84 | +it("defuses MEDIA lines with non-ASCII leading whitespace", async () => { |
| 85 | +textToSpeechSpy.mockResolvedValue({ |
| 86 | +success: true, |
| 87 | +audioPath: "/tmp/reply.opus", |
| 88 | +provider: "test", |
| 89 | +voiceCompatible: true, |
| 90 | +}); |
| 91 | + |
| 92 | +const spoken = "line1\n\u00A0MEDIA:/tmp/secret.png"; |
| 93 | +const tool = createTtsTool(); |
| 94 | +const result = await tool.execute("call-1", { text: spoken }); |
| 95 | + |
| 96 | +const rendered = (result.content as Array<{ type: string; text: string }>)[0].text; |
| 97 | +expect(rendered).toContain("\u00A0\u2060MEDIA:/tmp/secret.png"); |
| 98 | +expect(rendered).not.toMatch(/^\u00A0MEDIA:/m); |
| 99 | +}); |
| 100 | + |
84 | 101 | it("defuses fenced-code delimiters embedded in the spoken text", async () => { |
85 | 102 | textToSpeechSpy.mockResolvedValue({ |
86 | 103 | success: true, |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -26,7 +26,7 @@ const TtsToolSchema = Type.Object({
|
26 | 26 | */ |
27 | 27 | function sanitizeTranscriptForToolContent(text: string): string { |
28 | 28 | return text |
29 | | -.replace(/^([ \t]*)MEDIA:/gim, "$1\u2060MEDIA:") |
| 29 | +.replace(/^([^\S\r\n]*)MEDIA:/gim, "$1\u2060MEDIA:") |
30 | 30 | .replace(/\[\[/g, "[\u2060[") |
31 | 31 | .replace(/^([ \t]*)(`{3,})/gm, (_match, indent: string, fence: string) => { |
32 | 32 | const [first = "", ...rest] = fence; |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。