diff --git a/http/etag.ts b/http/etag.ts index 32cc88d572b6..12db49e9cd4b 100644 --- a/http/etag.ts +++ b/http/etag.ts @@ -158,7 +158,11 @@ export async function eTag( ? calcFileInfo(entity, options) : calcEntity(entity, options)); - return tag ? weak ? `W/"${tag}"` : `"${tag}"` : undefined; + if (!tag) { + return undefined; + } + + return weak ? `W/"${tag}"` : `"${tag}"`; } const STAR_REGEXP = /^\s*\*\s*$/; diff --git a/http/etag_test.ts b/http/etag_test.ts index 3540c28742dd..5aaefe17997f 100644 --- a/http/etag_test.ts +++ b/http/etag_test.ts @@ -147,3 +147,17 @@ Deno.test({ } }, }); + +Deno.test({ + name: "eTag() returns undefined when calcFileInfo returns undefined", + async fn() { + { + const result = await eTag({ + mtime: null, + size: 1024, + }); + + assert(result === undefined); + } + }, +});