From 28ee12ba15457a67bfa2bc5dfb132f08540e41b4 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 10 Feb 2026 04:08:59 +0000 Subject: [PATCH] Handle lowercase weak ETag validators consistently Co-authored-by: Theo Browne --- apps/t3/src/cli.test.ts | 3 +++ apps/t3/src/cli.ts | 12 ++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/apps/t3/src/cli.test.ts b/apps/t3/src/cli.test.ts index a64279ae0b..25c42984c5 100644 --- a/apps/t3/src/cli.test.ts +++ b/apps/t3/src/cli.test.ts @@ -980,6 +980,7 @@ describe("ifNoneMatchSatisfied", () => { it("matches weak and strong forms using weak comparison semantics", () => { expect(ifNoneMatchSatisfied("W/\"abc\"", "\"abc\"")).toBe(true); expect(ifNoneMatchSatisfied("\"abc\"", "W/\"abc\"")).toBe(true); + expect(ifNoneMatchSatisfied("w/\"abc\"", "\"abc\"")).toBe(true); }); it("does not match non-identical etags", () => { @@ -1008,6 +1009,7 @@ describe("ifMatchSatisfied", () => { it("rejects weak validators and mismatches", () => { expect(ifMatchSatisfied("W/\"abc\"", "\"abc\"")).toBe(false); + expect(ifMatchSatisfied("w/\"abc\"", "\"abc\"")).toBe(false); expect(ifMatchSatisfied("\"xyz\"", "\"abc\"")).toBe(false); }); @@ -1075,6 +1077,7 @@ describe("ifRangeSatisfied", () => { expect(ifRangeSatisfied("\"abc\"", "\"abc\"", Date.now())).toBe(true); expect(ifRangeSatisfied("\"abc\"", "\"xyz\"", Date.now())).toBe(false); expect(ifRangeSatisfied("W/\"abc\"", "\"abc\"", Date.now())).toBe(false); + expect(ifRangeSatisfied("w/\"abc\"", "\"abc\"", Date.now())).toBe(false); }); it("rejects wildcard etag values", () => { diff --git a/apps/t3/src/cli.ts b/apps/t3/src/cli.ts index 697756d655..84d179fab8 100644 --- a/apps/t3/src/cli.ts +++ b/apps/t3/src/cli.ts @@ -516,9 +516,13 @@ function staticEtagFor(stats: fs.Stats): string { return `"${stats.size.toString(16)}-${Math.trunc(stats.mtimeMs).toString(16)}"`; } +function isWeakEtag(value: string): boolean { + return /^w\//i.test(value.trim()); +} + function normalizeWeakEtag(etag: string): string { const trimmed = etag.trim(); - return trimmed.startsWith("W/") ? trimmed.slice(2).trim() : trimmed; + return isWeakEtag(trimmed) ? trimmed.slice(2).trim() : trimmed; } function normalizeEtagHeaderValue(value: string | string[] | undefined): string[] { @@ -561,13 +565,13 @@ export function ifMatchSatisfied(ifMatchHeader: string | string[] | undefined, e } const normalizedCurrentTag = etag.trim(); - if (normalizedCurrentTag.startsWith("W/")) { + if (isWeakEtag(normalizedCurrentTag)) { return false; } return candidates.some((candidate) => { const normalizedCandidate = candidate.trim(); - if (normalizedCandidate.startsWith("W/")) { + if (isWeakEtag(normalizedCandidate)) { return false; } @@ -639,7 +643,7 @@ export function ifRangeSatisfied( if (trimmed.startsWith("\"")) { return trimmed === etag; } - if (trimmed.startsWith("W/")) { + if (isWeakEtag(trimmed)) { return false; }