From 0d41e21b0e9b46cc179eff42c215439fb672964b Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 5 Jan 2021 19:50:40 +0100 Subject: fix: align encoding APIs to spec using WPT (#9004) --- core/bindings.rs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'core') diff --git a/core/bindings.rs b/core/bindings.rs index d9c875e60..eb46e6ef2 100644 --- a/core/bindings.rs +++ b/core/bindings.rs @@ -654,6 +654,14 @@ fn decode( ) }; + // Strip BOM + let buf = + if buf.len() >= 3 && buf[0] == 0xef && buf[1] == 0xbb && buf[2] == 0xbf { + &buf[3..] + } else { + buf + }; + // If `String::new_from_utf8()` returns `None`, this means that the // length of the decoded string would be longer than what V8 can // handle. In this case we return `RangeError`. -- cgit v1.2.3