fix(cron): reject durations that overflow to a non-finite value (#89448) · openclaw/openclaw@0b80732
Alix-007
·
2026-06-11
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -7,6 +7,7 @@ import {
|
7 | 7 | getCronChannelOptions, |
8 | 8 | parseAt, |
9 | 9 | parseCronToolsAllow, |
| 10 | +parseDurationMs, |
10 | 11 | printCronList, |
11 | 12 | } from "./shared.js"; |
12 | 13 | |
@@ -314,3 +315,26 @@ describe("coerceCronDeliveryPreviews", () => {
|
314 | 315 | ).toBe(0); |
315 | 316 | }); |
316 | 317 | }); |
| 318 | + |
| 319 | +describe("parseDurationMs", () => { |
| 320 | +it("parses valid positive durations", () => { |
| 321 | +expect(parseDurationMs("500ms")).toBe(500); |
| 322 | +expect(parseDurationMs("30s")).toBe(30_000); |
| 323 | +expect(parseDurationMs("1.5h")).toBe(5_400_000); |
| 324 | +expect(parseDurationMs("1d")).toBe(86_400_000); |
| 325 | +}); |
| 326 | + |
| 327 | +it("rejects non-positive and malformed durations", () => { |
| 328 | +expect(parseDurationMs("0s")).toBeNull(); |
| 329 | +expect(parseDurationMs("-5s")).toBeNull(); |
| 330 | +expect(parseDurationMs("abc")).toBeNull(); |
| 331 | +expect(parseDurationMs("")).toBeNull(); |
| 332 | +}); |
| 333 | + |
| 334 | +it("rejects durations that overflow to a non-finite millisecond value (#83906)", () => { |
| 335 | +// A finite mantissa can still overflow once multiplied by a large unit factor. |
| 336 | +expect(parseDurationMs(`1${"0".repeat(302)}d`)).toBeNull(); |
| 337 | +// A large-but-finite result is still accepted. |
| 338 | +expect(parseDurationMs(`9${"0".repeat(15)}ms`)).toBe(9_000_000_000_000_000); |
| 339 | +}); |
| 340 | +}); |
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。