fix(polls): centralize duration string parsing · openclaw/openclaw@36b0b12
steipete
·
2026-05-29
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -26,12 +26,14 @@ describe("poll params", () => {
|
26 | 26 | it("treats non-zero finite numeric poll params as poll creation intent", () => { |
27 | 27 | expect(hasPollCreationParams({ pollDurationSeconds: 60 })).toBe(true); |
28 | 28 | expect(hasPollCreationParams({ pollDurationSeconds: "60" })).toBe(true); |
| 29 | +expect(hasPollCreationParams({ pollDurationSeconds: "+60" })).toBe(true); |
29 | 30 | expect(hasPollCreationParams({ pollDurationSeconds: "1e3" })).toBe(true); |
30 | 31 | expect(hasPollCreationParams({ pollDurationHours: -1 })).toBe(true); |
31 | 32 | expect(hasPollCreationParams({ pollDurationSeconds: "-5" })).toBe(true); |
32 | 33 | expect(hasPollCreationParams({ pollDurationHours: Number.NaN })).toBe(false); |
33 | 34 | expect(hasPollCreationParams({ pollDurationSeconds: Infinity })).toBe(false); |
34 | 35 | expect(hasPollCreationParams({ pollDurationSeconds: "60abc" })).toBe(false); |
| 36 | +expect(hasPollCreationParams({ pollDurationSeconds: "0x10" })).toBe(false); |
35 | 37 | }); |
36 | 38 | |
37 | 39 | it("does not treat zero-valued numeric poll params as poll creation intent", () => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | import { readSnakeCaseParamRaw } from "./param-key.js"; |
| 2 | +import { parseStrictFiniteNumber } from "./shared/number-coercion.js"; |
2 | 3 | import { normalizeLowercaseStringOrEmpty } from "./shared/string-coerce.js"; |
3 | 4 | |
4 | 5 | type PollCreationParamKind = "string" | "stringArray" | "positiveInteger" | "boolean"; |
@@ -61,7 +62,7 @@ function hasExplicitUnknownPollValue(key: string, value: unknown): boolean {
|
61 | 62 | return false; |
62 | 63 | } |
63 | 64 | if (normalizePollParamKey(key).includes("duration")) { |
64 | | -const parsed = Number(trimmed); |
| 65 | +const parsed = parseStrictFiniteNumber(trimmed); |
65 | 66 | return Number.isFinite(parsed) && parsed !== 0; |
66 | 67 | } |
67 | 68 | const normalized = normalizeLowercaseStringOrEmpty(trimmed); |
@@ -100,8 +101,8 @@ export function hasPollCreationParams(params: Record<string, unknown>): boolean
|
100 | 101 | } |
101 | 102 | if (typeof value === "string") { |
102 | 103 | const trimmed = value.trim(); |
103 | | -const parsed = Number(trimmed); |
104 | | -if (trimmed.length > 0 && Number.isFinite(parsed) && parsed !== 0) { |
| 104 | +const parsed = parseStrictFiniteNumber(trimmed); |
| 105 | +if (parsed !== undefined && parsed !== 0) { |
105 | 106 | return true; |
106 | 107 | } |
107 | 108 | } |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。