Merge pull request #3325 from jdm/jsdecode

Don't fail converting invalid UTF8 when fetching JS source. Fixes #3302.
This commit is contained in:
Patrick Walton 2014-09-13 12:06:13 -07:00
commit 97e068b1c2
2 changed files with 10 additions and 2 deletions

View file

@ -28,7 +28,11 @@ pub fn factory(mut load_data: LoadData, start_chan: Sender<LoadResponse>) {
// FIXME: Find a way to load this without relying on the `../src` directory.
let mut path = os::self_exe_path().expect("can't get exe path");
path.pop();
path.push_many(["src", "test", "html", "failure.html"]);
if !path.join(Path::new("./tests/")).is_dir() {
path.pop();
}
path.push_many(["tests", "html", "failure.html"]);
assert!(path.exists());
load_data.url = Url::from_file_path(&path).unwrap();
}
_ => {

View file

@ -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<HtmlDiscoveryMessage>,
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,
});
}