nomagick commited on
Commit
c795cdb
·
unverified ·
1 Parent(s): ec9f082

fix: the other way of setting charset in html

Browse files
Files changed (1) hide show
  1. src/services/snapshot-formatter.ts +4 -1
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
- const innerCharset = snapshot.html.slice(0, 1024).match(/<meta[^>]+text\/html;\s*?charset=([^>"]+)\"/i)?.[1]?.toLowerCase();
 
 
 
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
  }