fix: parse voice call cli integers strictly · openclaw/openclaw@8ec4a72
steipete
·
2026-05-29
·
via Recent Commits to openclaw:main
File tree
extensions/voice-call/src
| Original file line number | Diff line number | Diff line change |
|---|
@@ -10,3 +10,19 @@ describe("voice-call CLI gateway fallback", () => {
|
10 | 10 | ).toBe(true); |
11 | 11 | }); |
12 | 12 | }); |
| 13 | + |
| 14 | +describe("parseVoiceCallIntOption", () => { |
| 15 | +it("parses decimal integer option values", () => { |
| 16 | +expect(testing.parseVoiceCallIntOption("250", "--poll", { min: 50 })).toBe(250); |
| 17 | +expect(testing.parseVoiceCallIntOption(" 25 ", "--since")).toBe(25); |
| 18 | +}); |
| 19 | + |
| 20 | +it("rejects non-decimal JavaScript numeric syntax", () => { |
| 21 | +expect(() => testing.parseVoiceCallIntOption("0x10", "--last")).toThrow( |
| 22 | +"Invalid numeric value for --last: 0x10", |
| 23 | +); |
| 24 | +expect(() => testing.parseVoiceCallIntOption("1e3", "--last")).toThrow( |
| 25 | +"Invalid numeric value for --last: 1e3", |
| 26 | +); |
| 27 | +}); |
| 28 | +}); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -54,6 +54,7 @@ const VOICE_CALL_GATEWAY_DEFAULT_TIMEOUT_MS = 5000;
|
54 | 54 | const VOICE_CALL_GATEWAY_OPERATION_TIMEOUT_MS = 30000; |
55 | 55 | const VOICE_CALL_GATEWAY_TRANSCRIPT_BUFFER_MS = 10000; |
56 | 56 | const VOICE_CALL_GATEWAY_POLL_INTERVAL_MS = 1000; |
| 57 | +const DECIMAL_INTEGER_RE = /^\d+$/; |
57 | 58 | |
58 | 59 | const voiceCallCliDeps = { |
59 | 60 | callGatewayFromCli, |
@@ -81,7 +82,8 @@ function parseVoiceCallIntOption(
|
81 | 82 | opts?: { min?: number }, |
82 | 83 | ): number { |
83 | 84 | const min = opts?.min ?? 0; |
84 | | -const parsed = Number(raw); |
| 85 | +const value = raw?.trim() ?? ""; |
| 86 | +const parsed = DECIMAL_INTEGER_RE.test(value) ? Number(value) : Number.NaN; |
85 | 87 | if (!Number.isInteger(parsed) || parsed < min) { |
86 | 88 | throw new Error(`Invalid numeric value for ${optionName}: ${raw ?? ""}`); |
87 | 89 | } |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。