From c795cdb7b33c2882695b7b09bd3c66fd4365f8d2 Mon Sep 17 00:00:00 2001 From: Yanlong Wang Date: Thu, 17 Apr 2025 22:04:06 +0800 Subject: [PATCH] fix: the other way of setting charset in html --- src/services/snapshot-formatter.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/services/snapshot-formatter.ts b/src/services/snapshot-formatter.ts index fbc06b5..3064a88 100644 --- a/src/services/snapshot-formatter.ts +++ b/src/services/snapshot-formatter.ts @@ -827,7 +827,10 @@ ${suffixMixins.length ? `\n${suffixMixins.join('\n\n')}\n` : ''}`; throw new AssertionFailureError(`Failed to access ${url}: file too large`); } snapshot.html = await readFile(await file.filePath, encoding); - const innerCharset = snapshot.html.slice(0, 1024).match(/]+text\/html;\s*?charset=([^>"]+)\"/i)?.[1]?.toLowerCase(); + let innerCharset; + const peek = snapshot.html.slice(0, 1024); + innerCharset ??= peek.match(/]+text\/html;\s*?charset=([^>"]+)/i)?.[1]?.toLowerCase(); + innerCharset ??= peek.match(/]+charset="([^>"]+)\"/i)?.[1]?.toLowerCase(); if (innerCharset && innerCharset !== encoding) { snapshot.html = await readFile(await file.filePath, innerCharset); }