fix(agent-core): preserve empty prompt arguments (#96405) · openclaw/openclaw@c030b30
lin-hongkuan
·
2026-06-25
·
via Recent Commits to openclaw:main
File tree
packages/agent-core/src/harness
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Agent Core tests cover prompt template argument parsing behavior. |
| 2 | +import { describe, expect, it } from "vitest"; |
| 3 | +import { parseCommandArgs, substituteArgs } from "./prompt-template-arguments.js"; |
| 4 | + |
| 5 | +describe("prompt template arguments", () => { |
| 6 | +it("preserves quoted empty arguments so positional placeholders stay aligned", () => { |
| 7 | +expect(parseCommandArgs('first "" third')).toEqual(["first", "", "third"]); |
| 8 | +expect(parseCommandArgs("first '' third")).toEqual(["first", "", "third"]); |
| 9 | +expect(substituteArgs("$1|$2|$3", parseCommandArgs('first "" third'))).toBe("first||third"); |
| 10 | +}); |
| 11 | +}); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -5,26 +5,31 @@ export function parseCommandArgs(argsString: string): string[] {
|
5 | 5 | const args: string[] = []; |
6 | 6 | let current = ""; |
7 | 7 | let inQuote: string | null = null; |
| 8 | +let hasToken = false; |
8 | 9 | |
9 | 10 | for (const char of argsString) { |
10 | 11 | if (inQuote) { |
11 | 12 | if (char === inQuote) { |
12 | 13 | inQuote = null; |
13 | 14 | } else { |
| 15 | +hasToken = true; |
14 | 16 | current += char; |
15 | 17 | } |
16 | 18 | } else if (char === '"' || char === "'") { |
| 19 | +hasToken = true; |
17 | 20 | inQuote = char; |
18 | 21 | } else if (/\s/.test(char)) { |
19 | | -if (current) { |
| 22 | +if (hasToken) { |
20 | 23 | args.push(current); |
21 | 24 | current = ""; |
| 25 | +hasToken = false; |
22 | 26 | } |
23 | 27 | } else { |
| 28 | +hasToken = true; |
24 | 29 | current += char; |
25 | 30 | } |
26 | 31 | } |
27 | | -if (current) { |
| 32 | +if (hasToken) { |
28 | 33 | args.push(current); |
29 | 34 | } |
30 | 35 | return args; |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。