From 8748818b7e11e910a95d34eb9ed5865c5ea101cf Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Sat, 13 Sep 2014 11:22:29 -0400 Subject: [PATCH] Don't fail converting invalid UTF8 when fetching JS source. Fixes #3302. --- components/script/html/hubbub_html_parser.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/components/script/html/hubbub_html_parser.rs b/components/script/html/hubbub_html_parser.rs index 6862ef4a492..89d817b9380 100644 --- a/components/script/html/hubbub_html_parser.rs +++ b/components/script/html/hubbub_html_parser.rs @@ -20,6 +20,9 @@ use dom::types::*; use html::cssparse::{StylesheetProvenance, UrlProvenance, spawn_css_parser}; use page::Page; +use encoding::all::UTF_8; +use encoding::types::{Encoding, DecodeReplace}; + use hubbub::hubbub; use hubbub::hubbub::{NullNs, HtmlNs, MathMlNs, SvgNs, XLinkNs, XmlNs, XmlNsNs}; use servo_net::resource_task::{Load, LoadData, Payload, Done, ResourceTask, load_whole_resource}; @@ -142,8 +145,9 @@ fn js_script_listener(to_parent: Sender, error!("error loading script {:s}", url.serialize()); } Ok((metadata, bytes)) => { + let decoded = UTF_8.decode(bytes.as_slice(), DecodeReplace).unwrap(); result_vec.push(JSFile { - data: String::from_utf8(bytes).unwrap().to_string(), + data: decoded.to_string(), url: metadata.final_url, }); }