I've been working with a lot of charsets lately and I discovered a lot of issues when trying to establish the proper charset for a random web page.
The charset can be set in the headers of the html document, or inside the <head>
section, multiple times or sometimes the declaration is omitted. Despite these issues chrome dose a great job at setting the best charset every time.
I've tried searching the sources but didn't manage to find anything as I don't know where to look.
So my question is where could I find the algorithm?
Thanks
problematic example:
HTTP header of a document (based on server configurations):Content-type: text/html; charset=utf-8
and the document looks like:
<?xml version="1.0" encoding="ISO-8859-1"?>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-type" content="text/html;charset=ISO-8859-1" />
</head>
<body>...</body>
</html>
Which encoding would be used to render the text?
Chrome uses https://github.com/google/compact_enc_det
If you want to read the actual code that calls that project, the function is DetectTextEncoding
in the file third_party/blink/renderer/platform/text/text_encoding_detector.cc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With