nomagick commited on
Commit
75a4dbd
·
unverified ·
1 Parent(s): 5f83d86

fix: meta charset hint

Browse files
Files changed (1) hide show
  1. src/services/snapshot-formatter.ts +4 -0
src/services/snapshot-formatter.ts CHANGED
@@ -827,6 +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
  return snapshot;
832
  }
 
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
+ }
834
 
835
  return snapshot;
836
  }