mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-10 16:51:13 +00:00
fix: preserve input file whitespace
This commit is contained in:
@@ -466,8 +466,42 @@ describe("OpenResponses HTTP API (e2e)", () => {
|
||||
(optsInputFile as { extraSystemPrompt?: string } | undefined)?.extraSystemPrompt ?? "";
|
||||
expect(inputFileMessage).toBe("read this");
|
||||
expect(inputFilePrompt).toContain('<file name="hello.txt">');
|
||||
expect(inputFilePrompt).toContain('<<<EXTERNAL_UNTRUSTED_CONTENT id="');
|
||||
expect(inputFilePrompt).toContain("Source: External");
|
||||
await ensureResponseConsumed(resInputFile);
|
||||
|
||||
mockAgentOnce([{ text: "ok" }]);
|
||||
const resInputFileWhitespace = await postResponses(port, {
|
||||
model: "openclaw",
|
||||
input: [
|
||||
{
|
||||
type: "message",
|
||||
role: "user",
|
||||
content: [
|
||||
{ type: "input_text", text: "read this" },
|
||||
{
|
||||
type: "input_file",
|
||||
source: {
|
||||
type: "base64",
|
||||
media_type: "text/plain",
|
||||
data: Buffer.from(" hello ").toString("base64"),
|
||||
filename: "spaces.txt",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(resInputFileWhitespace.status).toBe(200);
|
||||
const optsInputFileWhitespace = (agentCommand.mock.calls[0] as unknown[] | undefined)?.[0];
|
||||
const inputFileWhitespacePrompt =
|
||||
(optsInputFileWhitespace as { extraSystemPrompt?: string } | undefined)
|
||||
?.extraSystemPrompt ?? "";
|
||||
expect(inputFileWhitespacePrompt).toContain('<file name="spaces.txt">');
|
||||
expect(inputFileWhitespacePrompt).toContain("\n hello \n");
|
||||
expect(inputFileWhitespacePrompt).toContain('<<<EXTERNAL_UNTRUSTED_CONTENT id="');
|
||||
await ensureResponseConsumed(resInputFileWhitespace);
|
||||
|
||||
mockAgentOnce([{ text: "ok" }]);
|
||||
const resInputFileInjection = await postResponses(port, {
|
||||
model: "openclaw",
|
||||
|
||||
@@ -602,12 +602,12 @@ export async function handleOpenResponsesHttpRequest(
|
||||
},
|
||||
limits: limits.files,
|
||||
});
|
||||
const text = file.text?.trim();
|
||||
if (text) {
|
||||
const rawText = file.text;
|
||||
if (rawText?.trim()) {
|
||||
fileContexts.push(
|
||||
renderFileContextBlock({
|
||||
filename: file.filename,
|
||||
content: wrapUntrustedFileContent(text),
|
||||
content: wrapUntrustedFileContent(rawText),
|
||||
}),
|
||||
);
|
||||
} else if (file.images && file.images.length > 0) {
|
||||
|
||||
Reference in New Issue
Block a user