fix: meta charset hint

This commit is contained in:
Yanlong Wang 2025-04-11 22:36:49 +08:00
parent 5f83d862dd
commit 75a4dbdd79
No known key found for this signature in database
GPG Key ID: C0A623C0BADF9F37

View File

@ -827,6 +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(/<meta[^>]+text\/html;\s*?charset=([^>"]+)\"/i)?.[1]?.toLowerCase();
if (innerCharset && innerCharset !== encoding) {
snapshot.html = await readFile(await file.filePath, innerCharset);
}
return snapshot;
}