Skip to content

Commit da48a97

Browse files
Merge branch 'main' into build/deterministic-npm-toolchain-on-main
2 parents ebde372 + f07f3ce commit da48a97

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/rate-limit.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ function jsonResponse(body: unknown, status = 200): Response {
5555
export function configuredDistributedRateLimit(raw: string | undefined): number {
5656
const parsed = Number(raw ?? String(DEFAULT_RATE_LIMIT_PER_MINUTE));
5757
if (!Number.isFinite(parsed) || parsed <= 0) return DEFAULT_RATE_LIMIT_PER_MINUTE;
58-
return Math.min(Math.floor(parsed), MAX_RATE_LIMIT_PER_MINUTE);
58+
const normalized = Math.floor(parsed);
59+
if (normalized <= 0) return DEFAULT_RATE_LIMIT_PER_MINUTE;
60+
return Math.min(normalized, MAX_RATE_LIMIT_PER_MINUTE);
5961
}
6062

6163
function canonicalIpv4(candidate: string): string | undefined {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { describe, expect, it } from "vitest";
2+
import { configuredDistributedRateLimit } from "../src/rate-limit";
3+
4+
describe("distributed rate-limit configuration regression", () => {
5+
it("never normalizes a positive sub-unit rate limit to zero", () => {
6+
expect(configuredDistributedRateLimit("0.5")).toBe(60);
7+
expect(configuredDistributedRateLimit("0.999999")).toBe(60);
8+
});
9+
10+
it("preserves the existing floor semantics once the configured value can yield a positive integer", () => {
11+
expect(configuredDistributedRateLimit("1")).toBe(1);
12+
expect(configuredDistributedRateLimit("1.9")).toBe(1);
13+
});
14+
});

0 commit comments

Comments
 (0)