Fix outbound confirmation and verification safety
This commit is contained in:
1 parent
b17bd09194
commit
67a461452c
20 files changed
+313
-74
No files matched your search
@@ -26,6 +26,8 @@ describe("tokenizeDuration", () => {
|
||||
expect(tokenizeDuration("5parsecs")).toBeUndefined();
|
||||
expect(tokenizeDuration(Number.NaN)).toBeUndefined();
|
||||
expect(tokenizeDuration(true as unknown as string)).toBeUndefined();
|
||||
expect(tokenizeDuration("9".repeat(309))).toBeUndefined();
|
||||
expect(tokenizeDuration("9".repeat(309) + "s")).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -71,5 +73,7 @@ describe("parseDurationMs", () => {
|
||||
test("falls back rather than failing a batch over a bad poll interval", () => {
|
||||
expect(parseDurationMs("soon")).toBe(600_000);
|
||||
expect(parseDurationMs("soon", 1000)).toBe(1000);
|
||||
expect(parseDurationMs("9".repeat(309) + "s", 1000)).toBe(1000);
|
||||
expect(parseDurationMs("9".repeat(308) + "d", 1000)).toBe(1000);
|
||||
});
|
||||
});
|
||||
@@ -74,9 +74,14 @@ export function tokenizeDuration(
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const magnitude = parseFloat(match[1]);
|
||||
if (!Number.isFinite(magnitude)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const rawUnit = match[2]?.toLowerCase();
|
||||
if (!rawUnit) {
|
||||
return { value: parseFloat(match[1]), unit: undefined };
|
||||
return { value: magnitude, unit: undefined };
|
||||
}
|
||||
|
||||
const unit = UNIT_ALIASES[rawUnit];
|
||||
@@ -86,7 +91,7 @@ export function tokenizeDuration(
|
||||
if (options.units && !options.units.includes(unit)) {
|
||||
return undefined;
|
||||
}
|
||||
return { value: parseFloat(match[1]), unit };
|
||||
return { value: magnitude, unit };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,5 +140,6 @@ export function parseDurationMs(duration: string, fallbackMs = DEFAULT_DURATION_
|
||||
if (!token || token.value < 0) {
|
||||
return fallbackMs;
|
||||
}
|
||||
return Math.round(durationSeconds(token, "s") * 1000);
|
||||
const milliseconds = Math.round(durationSeconds(token, "s") * 1000);
|
||||
return Number.isFinite(milliseconds) ? milliseconds : fallbackMs;
|
||||
}
|
||||
Reference in new issue
Block a user