Skip to content

Commit

Permalink
Make document's character encoding reflect byte order mark
Browse files Browse the repository at this point in the history
This change fixes a bug where document's character encoding was set to the return value of the encoding sniffing algorithm rather than to the actual encoding used, which differed when the stream started with a byte order mark. This change incorporates BOM sniffing into the encoding sniffing algorithm, ensuring both encodings are identical.

Tests: web-platform-tests/wpt#22276.

Closes #1077.
  • Loading branch information
Andreu Botella authored Mar 24, 2020
1 parent 59ee34d commit 21b5234
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -2497,6 +2497,9 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute

<li>The <dfn data-x-href="https://encoding.spec.whatwg.org/#utf-8-encode">UTF-8 encode</dfn>
algorithm which takes a character stream and returns a byte stream</li>

<li>The <dfn data-x-href="https://encoding.spec.whatwg.org/#bom-sniff">BOM sniff</dfn>
algorithm which takes a byte stream and returns an encoding or null.</li>
</ul>

</dd>
Expand Down Expand Up @@ -104983,6 +104986,16 @@ dictionary <dfn>StorageEventInit</dfn> : <span>EventInit</span> {

<ol>

<li>
<p>If the result of <span data-x="BOM sniff">BOM sniffing</span> is an encoding, return that
encoding with <span data-x="concept-encoding-confidence">confidence</span> <i>certain</i>.</p>

<p class="note">Although the <span>decode</span> algorithm will itself change the encoding to
use based on the presence of a byte order mark, this algorithm sniffs the BOM as well in order
to set the correct <span>document's character encoding</span> and <span
data-x="concept-encoding-confidence">confidence</span>.</p>
</li>

<li>

<p>If the user has explicitly instructed the user agent to override the document's character
Expand Down

0 comments on commit 21b5234

Please sign in to comment.