Spaces:
Build error
Build error
fix: the other way of setting charset in html
Browse files
src/services/snapshot-formatter.ts
CHANGED
|
@@ -827,7 +827,10 @@ ${suffixMixins.length ? `\n${suffixMixins.join('\n\n')}\n` : ''}`;
|
|
| 827 |
throw new AssertionFailureError(`Failed to access ${url}: file too large`);
|
| 828 |
}
|
| 829 |
snapshot.html = await readFile(await file.filePath, encoding);
|
| 830 |
-
|
|
|
|
|
|
|
|
|
|
| 831 |
if (innerCharset && innerCharset !== encoding) {
|
| 832 |
snapshot.html = await readFile(await file.filePath, innerCharset);
|
| 833 |
}
|
|
|
|
| 827 |
throw new AssertionFailureError(`Failed to access ${url}: file too large`);
|
| 828 |
}
|
| 829 |
snapshot.html = await readFile(await file.filePath, encoding);
|
| 830 |
+
let innerCharset;
|
| 831 |
+
const peek = snapshot.html.slice(0, 1024);
|
| 832 |
+
innerCharset ??= peek.match(/<meta[^>]+text\/html;\s*?charset=([^>"]+)/i)?.[1]?.toLowerCase();
|
| 833 |
+
innerCharset ??= peek.match(/<meta[^>]+charset="([^>"]+)\"/i)?.[1]?.toLowerCase();
|
| 834 |
if (innerCharset && innerCharset !== encoding) {
|
| 835 |
snapshot.html = await readFile(await file.filePath, innerCharset);
|
| 836 |
}
|