Replace rust-encoding with encoding-rs

This commit is contained in:
Simon Sapin 2017-10-31 19:06:34 +01:00
parent 3c36a36cc9
commit a3971eb686
25 changed files with 95 additions and 462 deletions

65
Cargo.lock generated
View file

@ -797,63 +797,6 @@ dependencies = [
"x11 2.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "encoding"
version = "0.2.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"encoding-index-japanese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)",
"encoding-index-korean 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)",
"encoding-index-simpchinese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)",
"encoding-index-singlebyte 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)",
"encoding-index-tradchinese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "encoding-index-japanese"
version = "1.20141219.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "encoding-index-korean"
version = "1.20141219.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "encoding-index-simpchinese"
version = "1.20141219.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "encoding-index-singlebyte"
version = "1.20141219.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "encoding-index-tradchinese"
version = "1.20141219.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "encoding_index_tests"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "encoding_rs"
version = "0.7.1"
@ -2617,7 +2560,6 @@ dependencies = [
"devtools_traits 0.0.1",
"dom_struct 0.0.1",
"domobject_derive 0.0.1",
"encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
"encoding_rs 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.15.3 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3862,13 +3804,6 @@ dependencies = [
"checksum dwmapi-sys 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07c4c7cc7b396419bc0a4d90371d0cee16cb5053b53647d287c0b728000c41fe"
"checksum dwrote 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "36e3b27cd0b8a68e00f07e8d8e1e4f4d8a6b8b873290a734f63bd56d792d23e1"
"checksum either 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18785c1ba806c258137c937e44ada9ee7e69a37e3c72077542cd2f069d78562a"
"checksum encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "6b0d943856b990d12d3b55b359144ff341533e516d94098b1d3fc1ac666d36ec"
"checksum encoding-index-japanese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "04e8b2ff42e9a05335dbf8b5c6f7567e5591d0d916ccef4e0b1710d32a0d0c91"
"checksum encoding-index-korean 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "4dc33fb8e6bcba213fe2f14275f0963fd16f0a02c878e3095ecfdf5bee529d81"
"checksum encoding-index-simpchinese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d87a7194909b9118fc707194baa434a4e3b0fb6a5a757c73c3adb07aa25031f7"
"checksum encoding-index-singlebyte 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3351d5acffb224af9ca265f435b859c7c01537c0849754d3db3fdf2bfe2ae84a"
"checksum encoding-index-tradchinese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fd0e20d5688ce3cab59eb3ef3a2083a5c77bf496cb798dc6fcdb75f323890c18"
"checksum encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569"
"checksum encoding_rs 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f5215aabf22b83153be3ee44dfe3f940214541b2ce13d419c55e7a115c8c51a9"
"checksum energy-monitor 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fe872d0664f1cc60db36349af245d892ee67d3c8f78055df0ebc43271fd4e05c"
"checksum energymon 0.3.0 (git+https://github.com/energymon/energymon-rust.git)" = "<none>"

View file

@ -39,7 +39,6 @@ deny_public_fields = {path = "../deny_public_fields"}
devtools_traits = {path = "../devtools_traits"}
dom_struct = {path = "../dom_struct"}
domobject_derive = {path = "../domobject_derive"}
encoding = "0.2"
encoding_rs = "0.7"
euclid = "0.15"
fnv = "1.0"

View file

@ -46,7 +46,7 @@ use dom::bindings::root::{Dom, DomRoot};
use dom::bindings::str::{DOMString, USVString};
use dom::bindings::utils::WindowProxyHandler;
use dom::document::PendingRestyle;
use encoding::types::EncodingRef;
use encoding_rs::Encoding;
use euclid::{Transform2D, Transform3D, Point2D, Vector2D, Rect, TypedSize2D, ScaleFactor};
use euclid::Length as EuclidLength;
use html5ever::{Prefix, LocalName, Namespace, QualName};
@ -122,7 +122,7 @@ pub unsafe trait JSTraceable {
unsafe_no_jsmanaged_fields!(CSSError);
unsafe_no_jsmanaged_fields!(EncodingRef);
unsafe_no_jsmanaged_fields!(&'static Encoding);
unsafe_no_jsmanaged_fields!(Reflector);

View file

@ -90,8 +90,7 @@ use dom::webglcontextevent::WebGLContextEvent;
use dom::window::{ReflowReason, Window};
use dom::windowproxy::WindowProxy;
use dom_struct::dom_struct;
use encoding::EncodingRef;
use encoding::all::UTF_8;
use encoding_rs::{Encoding, UTF_8};
use euclid::Point2D;
use html5ever::{LocalName, Namespace, QualName};
use hyper::header::{Header, SetCookie};
@ -240,7 +239,7 @@ pub struct Document {
implementation: MutNullableDom<DOMImplementation>,
content_type: DOMString,
last_modified: Option<String>,
encoding: Cell<EncodingRef>,
encoding: Cell<&'static Encoding>,
has_browsing_context: bool,
is_html_document: bool,
activity: Cell<DocumentActivity>,
@ -576,11 +575,11 @@ impl Document {
}
}
pub fn encoding(&self) -> EncodingRef {
pub fn encoding(&self) -> &'static Encoding {
self.encoding.get()
}
pub fn set_encoding(&self, encoding: EncodingRef) {
pub fn set_encoding(&self, encoding: &'static Encoding) {
self.encoding.set(encoding);
}
@ -2828,34 +2827,7 @@ impl DocumentMethods for Document {
// https://dom.spec.whatwg.org/#dom-document-characterset
fn CharacterSet(&self) -> DOMString {
DOMString::from(match self.encoding.get().name() {
"utf-8" => "UTF-8",
"ibm866" => "IBM866",
"iso-8859-2" => "ISO-8859-2",
"iso-8859-3" => "ISO-8859-3",
"iso-8859-4" => "ISO-8859-4",
"iso-8859-5" => "ISO-8859-5",
"iso-8859-6" => "ISO-8859-6",
"iso-8859-7" => "ISO-8859-7",
"iso-8859-8" => "ISO-8859-8",
"iso-8859-8-i" => "ISO-8859-8-I",
"iso-8859-10" => "ISO-8859-10",
"iso-8859-13" => "ISO-8859-13",
"iso-8859-14" => "ISO-8859-14",
"iso-8859-15" => "ISO-8859-15",
"iso-8859-16" => "ISO-8859-16",
"koi8-r" => "KOI8-R",
"koi8-u" => "KOI8-U",
"gbk" => "GBK",
"big5" => "Big5",
"euc-jp" => "EUC-JP",
"iso-2022-jp" => "ISO-2022-JP",
"shift_jis" => "Shift_JIS",
"euc-kr" => "EUC-KR",
"utf-16be" => "UTF-16BE",
"utf-16le" => "UTF-16LE",
name => name
})
DOMString::from(self.encoding.get().name())
}
// https://dom.spec.whatwg.org/#dom-document-charset

View file

@ -21,9 +21,7 @@ use dom::eventtarget::EventTarget;
use dom::globalscope::GlobalScope;
use dom::progressevent::ProgressEvent;
use dom_struct::dom_struct;
use encoding::all::UTF_8;
use encoding::label::encoding_from_whatwg_label;
use encoding::types::{DecoderTrap, EncodingRef};
use encoding_rs::{Encoding, UTF_8};
use hyper::mime::{Attr, Mime};
use js::jsapi::Heap;
use js::jsapi::JSAutoCompartment;
@ -223,8 +221,8 @@ impl FileReader {
//https://w3c.github.io/FileAPI/#encoding-determination
// Steps 1 & 2 & 3
let mut encoding = blob_label.as_ref()
.map(|string| &**string)
.and_then(encoding_from_whatwg_label);
.map(|string| string.as_bytes())
.and_then(Encoding::for_label);
// Step 4 & 5
encoding = encoding.or_else(|| {
@ -232,16 +230,16 @@ impl FileReader {
resultmime.and_then(|Mime(_, _, ref parameters)| {
parameters.iter()
.find(|&&(ref k, _)| &Attr::Charset == k)
.and_then(|&(_, ref v)| encoding_from_whatwg_label(&v.to_string()))
.and_then(|&(_, ref v)| Encoding::for_label(v.as_str().as_bytes()))
})
});
// Step 6
let enc = encoding.unwrap_or(UTF_8 as EncodingRef);
let enc = encoding.unwrap_or(UTF_8);
let convert = blob_bytes;
// Step 7
let output = enc.decode(convert, DecoderTrap::Replace).unwrap();
let (output, _, _) = enc.decode(convert);
*result.borrow_mut() = Some(FileReaderResult::String(DOMString::from(output)));
}

View file

@ -42,9 +42,7 @@ use dom::node::{document_from_node, window_from_node};
use dom::validitystate::ValidationFlags;
use dom::virtualmethods::VirtualMethods;
use dom_struct::dom_struct;
use encoding::{EncodingRef, EncoderTrap};
use encoding::all::UTF_8;
use encoding::label::encoding_from_whatwg_label;
use encoding_rs::{Encoding, UTF_8};
use html5ever::{LocalName, Prefix};
use hyper::header::{Charset, ContentDisposition, ContentType, DispositionParam, DispositionType};
use hyper::method::Method;
@ -252,14 +250,15 @@ pub enum ResetFrom {
impl HTMLFormElement {
// https://html.spec.whatwg.org/multipage/#picking-an-encoding-for-the-form
fn pick_encoding(&self) -> EncodingRef {
fn pick_encoding(&self) -> &'static Encoding {
// Step 2
if self.upcast::<Element>().has_attribute(&local_name!("accept-charset")) {
// Substep 1
let input = self.upcast::<Element>().get_string_attribute(&local_name!("accept-charset"));
// Substep 2, 3, 4
let mut candidate_encodings = split_html_space_chars(&*input).filter_map(encoding_from_whatwg_label);
let mut candidate_encodings = split_html_space_chars(&*input)
.filter_map(|c| Encoding::for_label(c.as_bytes()));
// Substep 5, 6
return candidate_encodings.next().unwrap_or(UTF_8);
@ -278,7 +277,7 @@ impl HTMLFormElement {
let encoding = self.pick_encoding();
// Step 3
let charset = &*encoding.whatwg_name().unwrap();
let charset = encoding.name();
for entry in form_data.iter_mut() {
// Step 4, 5
@ -377,8 +376,8 @@ impl HTMLFormElement {
}
// https://html.spec.whatwg.org/multipage/#submit-mutate-action
fn mutate_action_url(&self, form_data: &mut Vec<FormDatum>, mut load_data: LoadData, encoding: EncodingRef) {
let charset = &*encoding.whatwg_name().unwrap();
fn mutate_action_url(&self, form_data: &mut Vec<FormDatum>, mut load_data: LoadData, encoding: &'static Encoding) {
let charset = encoding.name();
self.set_encoding_override(load_data.url.as_mut_url().query_pairs_mut())
.clear()
@ -390,11 +389,11 @@ impl HTMLFormElement {
// https://html.spec.whatwg.org/multipage/#submit-body
fn submit_entity_body(&self, form_data: &mut Vec<FormDatum>, mut load_data: LoadData,
enctype: FormEncType, encoding: EncodingRef) {
enctype: FormEncType, encoding: &'static Encoding) {
let boundary = generate_boundary();
let bytes = match enctype {
FormEncType::UrlEncoded => {
let charset = &*encoding.whatwg_name().unwrap();
let charset = encoding.name();
load_data.headers.set(ContentType::form_url_encoded());
self.set_encoding_override(load_data.url.as_mut_url().query_pairs_mut())
@ -422,11 +421,7 @@ impl HTMLFormElement {
fn set_encoding_override<'a>(&self, mut serializer: Serializer<UrlQuery<'a>>)
-> Serializer<UrlQuery<'a>> {
let encoding = self.pick_encoding();
if encoding.name() != "utf-8" {
serializer.custom_encoding_override(move |s| {
encoding.encode(s, EncoderTrap::NcrEscape).unwrap().into()
});
}
serializer.custom_encoding_override(move |s| encoding.encode(s).0);
serializer
}
@ -1118,12 +1113,12 @@ impl FormControlElementHelpers for Element {
// https://html.spec.whatwg.org/multipage/#multipart/form-data-encoding-algorithm
pub fn encode_multipart_form_data(form_data: &mut Vec<FormDatum>,
boundary: String, encoding: EncodingRef) -> Vec<u8> {
boundary: String, encoding: &'static Encoding) -> Vec<u8> {
// Step 1
let mut result = vec![];
// Step 2
let charset = &*encoding.whatwg_name().unwrap_or("UTF-8");
let charset = encoding.name();
// Step 3
for entry in form_data.iter_mut() {

View file

@ -23,8 +23,7 @@ use dom::node::{ChildrenMutation, CloneChildrenFlag, Node};
use dom::node::{document_from_node, window_from_node};
use dom::virtualmethods::VirtualMethods;
use dom_struct::dom_struct;
use encoding::label::encoding_from_whatwg_label;
use encoding::types::{DecoderTrap, EncodingRef};
use encoding_rs::Encoding;
use html5ever::{LocalName, Prefix};
use ipc_channel::ipc;
use ipc_channel::router::ROUTER;
@ -147,7 +146,7 @@ struct ScriptContext {
kind: ExternalScriptKind,
/// The (fallback) character encoding argument to the "fetch a classic
/// script" algorithm.
character_encoding: EncodingRef,
character_encoding: &'static Encoding,
/// The response body received to date.
data: Vec<u8>,
/// The response metadata received to date.
@ -199,11 +198,11 @@ impl FetchResponseListener for ScriptContext {
// Step 6.
let encoding = metadata.charset
.and_then(|encoding| encoding_from_whatwg_label(&encoding))
.and_then(|encoding| Encoding::for_label(encoding.as_bytes()))
.unwrap_or(self.character_encoding);
// Step 7.
let source_text = encoding.decode(&self.data, DecoderTrap::Replace).unwrap();
let (source_text, _, _) = encoding.decode(&self.data);
ClassicScript::external(DOMString::from(source_text), metadata.final_url)
});
@ -232,7 +231,7 @@ fn fetch_a_classic_script(script: &HTMLScriptElement,
url: ServoUrl,
cors_setting: Option<CorsSettings>,
integrity_metadata: String,
character_encoding: EncodingRef) {
character_encoding: &'static Encoding) {
let doc = document_from_node(script);
// Step 1, 2.
@ -366,7 +365,7 @@ impl HTMLScriptElement {
// Step 14.
let encoding = element.get_attribute(&ns!(), &local_name!("charset"))
.and_then(|charset| encoding_from_whatwg_label(&charset.value()))
.and_then(|charset| Encoding::for_label(charset.value().as_bytes()))
.unwrap_or_else(|| doc.encoding());
// Step 15.

View file

@ -10,21 +10,20 @@ use dom::bindings::root::DomRoot;
use dom::bindings::str::{DOMString, USVString};
use dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
use encoding::label::encoding_from_whatwg_label;
use encoding::types::{DecoderTrap, EncodingRef};
use encoding_rs::Encoding;
use js::jsapi::{JSContext, JSObject};
use std::ascii::AsciiExt;
use std::borrow::ToOwned;
#[dom_struct]
pub struct TextDecoder {
reflector_: Reflector,
#[ignore_malloc_size_of = "Defined in rust-encoding"]
encoding: EncodingRef,
encoding: &'static Encoding,
fatal: bool,
}
impl TextDecoder {
fn new_inherited(encoding: EncodingRef, fatal: bool) -> TextDecoder {
fn new_inherited(encoding: &'static Encoding, fatal: bool) -> TextDecoder {
TextDecoder {
reflector_: Reflector::new(),
encoding: encoding,
@ -36,7 +35,7 @@ impl TextDecoder {
Err(Error::Range("The given encoding is not supported.".to_owned()))
}
pub fn new(global: &GlobalScope, encoding: EncodingRef, fatal: bool) -> DomRoot<TextDecoder> {
pub fn new(global: &GlobalScope, encoding: &'static Encoding, fatal: bool) -> DomRoot<TextDecoder> {
reflect_dom_object(Box::new(TextDecoder::new_inherited(encoding, fatal)),
global,
TextDecoderBinding::Wrap)
@ -47,19 +46,10 @@ impl TextDecoder {
label: DOMString,
options: &TextDecoderBinding::TextDecoderOptions)
-> Fallible<DomRoot<TextDecoder>> {
let encoding = match encoding_from_whatwg_label(&label) {
let encoding = match Encoding::for_label_no_replacement(label.as_bytes()) {
None => return TextDecoder::make_range_error(),
Some(enc) => enc
};
// The rust-encoding crate has WHATWG compatibility, so we are
// guaranteed to have a whatwg_name because we successfully got
// the encoding from encoding_from_whatwg_label.
// Use match + panic! instead of unwrap for better error message
match encoding.whatwg_name() {
None => panic!("Label {} fits valid encoding without valid name", label),
Some("replacement") => return TextDecoder::make_range_error(),
_ => ()
};
Ok(TextDecoder::new(global, encoding, options.fatal))
}
}
@ -68,7 +58,7 @@ impl TextDecoder {
impl TextDecoderMethods for TextDecoder {
// https://encoding.spec.whatwg.org/#dom-textdecoder-encoding
fn Encoding(&self) -> DOMString {
DOMString::from(self.encoding.whatwg_name().unwrap())
DOMString::from(self.encoding.name().to_ascii_lowercase())
}
// https://encoding.spec.whatwg.org/#dom-textdecoder-fatal
@ -93,15 +83,15 @@ impl TextDecoderMethods for TextDecoder {
}
};
let trap = if self.fatal {
DecoderTrap::Strict
let s = if self.fatal {
match self.encoding.decode_without_bom_handling_and_without_replacement(data.as_slice()) {
Some(s) => s,
None => return Err(Error::Type("Decoding failed".to_owned())),
}
} else {
DecoderTrap::Replace
let (s, _has_errors) = self.encoding.decode_without_bom_handling(data.as_slice());
s
};
match self.encoding.decode(data.as_slice(), trap) {
Ok(s) => Ok(USVString(s)),
Err(_) => Err(Error::Type("Decoding failed".to_owned())),
}
Ok(USVString(s.into_owned()))
}
}

View file

@ -36,9 +36,7 @@ use dom::workerglobalscope::WorkerGlobalScope;
use dom::xmlhttprequesteventtarget::XMLHttpRequestEventTarget;
use dom::xmlhttprequestupload::XMLHttpRequestUpload;
use dom_struct::dom_struct;
use encoding::all::UTF_8;
use encoding::label::encoding_from_whatwg_label;
use encoding::types::{DecoderTrap, EncoderTrap, Encoding, EncodingRef};
use encoding_rs::{Encoding, UTF_8};
use euclid::Length;
use html5ever::serialize;
use html5ever::serialize::SerializeOpts;
@ -66,6 +64,7 @@ use std::ascii::AsciiExt;
use std::borrow::ToOwned;
use std::cell::Cell;
use std::default::Default;
use std::slice;
use std::str;
use std::sync::{Arc, Mutex};
use task_source::networking::NetworkingTaskSource;
@ -137,8 +136,7 @@ pub struct XMLHttpRequest {
response_headers: DomRefCell<Headers>,
#[ignore_malloc_size_of = "Defined in hyper"]
override_mime_type: DomRefCell<Option<Mime>>,
#[ignore_malloc_size_of = "Defined in rust-encoding"]
override_charset: DomRefCell<Option<EncodingRef>>,
override_charset: DomRefCell<Option<&'static Encoding>>,
// Associated concepts
#[ignore_malloc_size_of = "Defined in hyper"]
@ -726,7 +724,7 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
// Step 4
let value = override_mime.get_param(mime::Attr::Charset);
*self.override_charset.borrow_mut() = value.and_then(|value| {
encoding_from_whatwg_label(value)
Encoding::for_label(value.as_bytes())
});
Ok(())
}
@ -1085,7 +1083,9 @@ impl XMLHttpRequest {
// According to Simon, decode() should never return an error, so unwrap()ing
// the result should be fine. XXXManishearth have a closer look at this later
// Step 1, 2, 6
charset.decode(&self.response.borrow(), DecoderTrap::Replace).unwrap()
let response = self.response.borrow();
let (text, _, _) = charset.decode(&response);
text.into_owned()
}
// https://xhr.spec.whatwg.org/#blob-response
@ -1164,8 +1164,22 @@ impl XMLHttpRequest {
return NullValue();
}
// Step 4
let json_text = UTF_8.decode(&bytes, DecoderTrap::Replace).unwrap();
let json_text: Vec<u16> = json_text.encode_utf16().collect();
fn decode_to_utf16(bytes: &[u8], encoding: &'static Encoding) -> Vec<u16> {
let mut decoder = encoding.new_decoder();
let capacity = decoder.max_utf16_buffer_length(bytes.len()).expect("Overflow");
let mut utf16 = Vec::with_capacity(capacity);
let extra = unsafe {
slice::from_raw_parts_mut(utf16.as_mut_ptr(), capacity)
};
let last = true;
let (_, read, written, _) = decoder.decode_to_utf16(bytes, extra, last);
assert!(read == bytes.len());
unsafe {
utf16.set_len(written)
}
utf16
}
let json_text = decode_to_utf16(&bytes, UTF_8);
// Step 5
rooted!(in(cx) let mut rval = UndefinedValue());
unsafe {
@ -1185,7 +1199,8 @@ impl XMLHttpRequest {
fn document_text_html(&self) -> DomRoot<Document> {
let charset = self.final_charset().unwrap_or(UTF_8);
let wr = self.global();
let decoded = charset.decode(&self.response.borrow(), DecoderTrap::Replace).unwrap();
let response = self.response.borrow();
let (decoded, _, _) = charset.decode(&response);
let document = self.new_doc(IsHTMLDocument::HTMLDocument);
// TODO: Disable scripting while parsing
ServoParser::parse_html_document(
@ -1198,7 +1213,8 @@ impl XMLHttpRequest {
fn handle_xml(&self) -> DomRoot<Document> {
let charset = self.final_charset().unwrap_or(UTF_8);
let wr = self.global();
let decoded = charset.decode(&self.response.borrow(), DecoderTrap::Replace).unwrap();
let response = self.response.borrow();
let (decoded, _, _) = charset.decode(&response);
let document = self.new_doc(IsHTMLDocument::NonHTMLDocument);
// TODO: Disable scripting while parsing
ServoParser::parse_xml_document(
@ -1307,7 +1323,7 @@ impl XMLHttpRequest {
Ok(())
}
fn final_charset(&self) -> Option<EncodingRef> {
fn final_charset(&self) -> Option<&'static Encoding> {
if self.override_charset.borrow().is_some() {
self.override_charset.borrow().clone()
} else {
@ -1315,7 +1331,7 @@ impl XMLHttpRequest {
Some(&ContentType(ref mime)) => {
let value = mime.get_param(mime::Attr::Charset);
value.and_then(|value|{
encoding_from_whatwg_label(value)
Encoding::for_label(value.as_bytes())
})
}
None => { None }
@ -1370,7 +1386,7 @@ impl Extractable for Blob {
impl Extractable for DOMString {
fn extract(&self) -> (Vec<u8>, Option<DOMString>) {
(UTF_8.encode(self, EncoderTrap::Replace).unwrap(),
(self.as_bytes().to_owned(),
Some(DOMString::from("text/plain;charset=UTF-8")))
}
}
@ -1378,8 +1394,7 @@ impl Extractable for DOMString {
impl Extractable for FormData {
fn extract(&self) -> (Vec<u8>, Option<DOMString>) {
let boundary = generate_boundary();
let bytes = encode_multipart_form_data(&mut self.datums(), boundary.clone(),
UTF_8 as EncodingRef);
let bytes = encode_multipart_form_data(&mut self.datums(), boundary.clone(), UTF_8);
(bytes, Some(DOMString::from(format!("multipart/form-data;boundary={}", boundary))))
}
}

View file

@ -34,7 +34,6 @@ extern crate devtools_traits;
extern crate dom_struct;
#[macro_use]
extern crate domobject_derive;
extern crate encoding;
extern crate encoding_rs;
extern crate euclid;
extern crate fnv;

View file

@ -1,5 +0,0 @@
[send-receive-utf16.htm]
type: testharness
[UTF-16 with BOM, no encoding in content-type]
expected: FAIL

View file

@ -1,51 +0,0 @@
[iso-2022-jp-decoder.html]
type: testharness
bug: https://github.com/servo/servo/issues/13239
[iso-2022-jp decoder: Error ESC]
expected: FAIL
[iso-2022-jp decoder: Double ASCII ESC, character]
expected: FAIL
[iso-2022-jp decoder: SO / SI]
expected: FAIL
[iso-2022-jp decoder: Roman ESC, characters]
expected: FAIL
[iso-2022-jp decoder: Roman ESC, SO / SI]
expected: FAIL
[iso-2022-jp decoder: Katakana ESC, multibyte ESC, character]
expected: FAIL
[iso-2022-jp decoder: Katakana ESC, error ESC, character]
expected: FAIL
[iso-2022-jp decoder: Katakana ESC, error ESC #2, character]
expected: FAIL
[iso-2022-jp decoder: Multibyte ESC, error ESC, character]
expected: FAIL
[iso-2022-jp decoder: Double multibyte ESC]
expected: FAIL
[iso-2022-jp decoder: Double multibyte ESC, character]
expected: FAIL
[iso-2022-jp decoder: Double multibyte ESC #2, character]
expected: FAIL
[iso-2022-jp decoder: Multibyte ESC, error ESC #2, character]
expected: FAIL
[iso-2022-jp decoder: Multibyte ESC, single byte, multibyte ESC, character]
expected: FAIL
[iso-2022-jp decoder: Multibyte ESC, lead error byte]
expected: FAIL
[iso-2022-jp decoder: character, error ESC #2]
expected: FAIL

View file

@ -1,20 +0,0 @@
[replacement-encodings.html]
type: testharness
[csiso2022kr - non-empty input decodes to one replacement character.]
expected: FAIL
[hz-gb-2312 - non-empty input decodes to one replacement character.]
expected: FAIL
[iso-2022-cn - non-empty input decodes to one replacement character.]
expected: FAIL
[iso-2022-cn-ext - non-empty input decodes to one replacement character.]
expected: FAIL
[iso-2022-kr - non-empty input decodes to one replacement character.]
expected: FAIL
[replacement - non-empty input decodes to one replacement character.]
expected: FAIL

View file

@ -1,5 +0,0 @@
[textdecoder-fatal-single-byte.html]
type: testharness
[Not throw: windows-1255 has a pointer 202]
expected: FAIL

View file

@ -1,60 +0,0 @@
[textdecoder-labels.html]
type: testharness
bug: https://github.com/servo/servo/issues/13232
["ms932" => "shift_jis"]
expected: FAIL
[" ms932" => "shift_jis"]
expected: FAIL
["ms932 " => "shift_jis"]
expected: FAIL
[" ms932 " => "shift_jis"]
expected: FAIL
["\\tms932" => "shift_jis"]
expected: FAIL
["ms932\\t" => "shift_jis"]
expected: FAIL
["\\tms932\\t" => "shift_jis"]
expected: FAIL
["\\nms932" => "shift_jis"]
expected: FAIL
["ms932\\n" => "shift_jis"]
expected: FAIL
["\\nms932\\n" => "shift_jis"]
expected: FAIL
["\\fms932" => "shift_jis"]
expected: FAIL
["ms932\\f" => "shift_jis"]
expected: FAIL
["\\fms932\\f" => "shift_jis"]
expected: FAIL
["\\rms932" => "shift_jis"]
expected: FAIL
["ms932\\r" => "shift_jis"]
expected: FAIL
["\\rms932\\r" => "shift_jis"]
expected: FAIL
[ms932 => shift_jis]
expected: FAIL
[koi8-ru => KOI8-U]
expected: FAIL
[ms932 => Shift_JIS]
expected: FAIL

View file

@ -1,17 +1,5 @@
[unsupported-encodings.html]
type: testharness
[UTF-32 with BOM should decode as UTF-16LE]
expected: FAIL
[utf-32 with BOM should decode as UTF-16LE]
expected: FAIL
[UTF-32LE with BOM should decode as UTF-16LE]
expected: FAIL
[utf-32le with BOM should decode as UTF-16LE]
expected: FAIL
[UTF-32be with BOM should decode as windows-1252]
expected: FAIL

View file

@ -1,5 +0,0 @@
[location-origin-idna.sub.window.html]
type: testharness
[Test that location.origin returns ASCII]
expected: FAIL

View file

@ -9,12 +9,6 @@
[Parsing origin: <http://你好你好> against <http://other.com/>]
expected: FAIL
[Parsing origin: <http://./> against <about:blank>]
expected: FAIL
[Parsing origin: <http://../> against <about:blank>]
expected: FAIL
[Parsing origin: <ftp://%e2%98%83> against <about:blank>]
expected: FAIL

View file

@ -9,12 +9,6 @@
[Parsing origin: <http://你好你好> against <http://other.com/>]
expected: FAIL
[Parsing origin: <http://./> against <about:blank>]
expected: FAIL
[Parsing origin: <http://../> against <about:blank>]
expected: FAIL
[Parsing origin: <ftp://%e2%98%83> against <about:blank>]
expected: FAIL

View file

@ -45,18 +45,6 @@
[Parsing: <http://:@www.example.com> against <about:blank>]
expected: FAIL
[Parsing: <http://[::1.2.3.4x\]> against <http://other.com/>]
expected: FAIL
[Parsing: <http://[::1.2.3.\]> against <http://other.com/>]
expected: FAIL
[Parsing: <http://[::1.2.\]> against <http://other.com/>]
expected: FAIL
[Parsing: <http://[::1.\]> against <http://other.com/>]
expected: FAIL
[Parsing: <sc://ñ.test/> against <about:blank>]
expected: FAIL
@ -174,12 +162,6 @@
[Parsing: <file://[1::8\]/C:/> against <about:blank>]
expected: FAIL
[Parsing: <http://./> against <about:blank>]
expected: FAIL
[Parsing: <http://../> against <about:blank>]
expected: FAIL
[Parsing: <https://0x100000000/test> against <about:blank>]
expected: FAIL

View file

@ -45,18 +45,6 @@
[Parsing: <http://:@www.example.com> against <about:blank>]
expected: FAIL
[Parsing: <http://[::1.2.3.4x\]> against <http://other.com/>]
expected: FAIL
[Parsing: <http://[::1.2.3.\]> against <http://other.com/>]
expected: FAIL
[Parsing: <http://[::1.2.\]> against <http://other.com/>]
expected: FAIL
[Parsing: <http://[::1.\]> against <http://other.com/>]
expected: FAIL
[Parsing: <sc://ñ.test/> against <about:blank>]
expected: FAIL
@ -174,12 +162,6 @@
[Parsing: <file://[1::8\]/C:/> against <about:blank>]
expected: FAIL
[Parsing: <http://./> against <about:blank>]
expected: FAIL
[Parsing: <http://../> against <about:blank>]
expected: FAIL
[Parsing: <https://0x100000000/test> against <about:blank>]
expected: FAIL

View file

@ -381,3 +381,21 @@
[01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.0123456789012345678901234567890123456789012345678.β (using <area>.hostname)]
expected: FAIL
[xn--1ug.example (using URL)]
expected: FAIL
[xn--1ug.example (using URL.host)]
expected: FAIL
[xn--1ug.example (using URL.hostname)]
expected: FAIL
[xn--1ug.example (using <a>)]
expected: FAIL
[xn--1ug.example (using <a>.host)]
expected: FAIL
[xn--1ug.example (using <a>.hostname)]
expected: FAIL

View file

@ -45,18 +45,6 @@
[Parsing: <http://:@www.example.com> against <about:blank>]
expected: FAIL
[Parsing: <http://[::1.2.3.4x\]> against <http://other.com/>]
expected: FAIL
[Parsing: <http://[::1.2.3.\]> against <http://other.com/>]
expected: FAIL
[Parsing: <http://[::1.2.\]> against <http://other.com/>]
expected: FAIL
[Parsing: <http://[::1.\]> against <http://other.com/>]
expected: FAIL
[Parsing: <sc://ñ.test/> against <about:blank>]
expected: FAIL
@ -174,12 +162,6 @@
[Parsing: <file://[1::8\]/C:/> against <about:blank>]
expected: FAIL
[Parsing: <http://./> against <about:blank>]
expected: FAIL
[Parsing: <http://../> against <about:blank>]
expected: FAIL
[Parsing: <https://0x100000000/test> against <about:blank>]
expected: FAIL

View file

@ -6,18 +6,3 @@
[Origin parsing: <https://faß.ExAmPlE/> against <about:blank>]
expected: FAIL
[Origin parsing: <http://你好你好> against <http://other.com/>]
expected: FAIL
[Origin parsing: <http://./> against <about:blank>]
expected: FAIL
[Origin parsing: <http://../> against <about:blank>]
expected: FAIL
[Origin parsing: <ftp://%e2%98%83> against <about:blank>]
expected: FAIL
[Origin parsing: <https://%e2%98%83> against <about:blank>]
expected: FAIL

View file

@ -567,39 +567,15 @@
[<area>: Setting <http://example.net/>.host = '[google.com\]' Broken IPv6]
expected: FAIL
[URL: Setting <http://example.net/>.host = '[::1.2.3.4x\]']
expected: FAIL
[<a>: Setting <http://example.net/>.host = '[::1.2.3.4x\]']
expected: FAIL
[<area>: Setting <http://example.net/>.host = '[::1.2.3.4x\]']
expected: FAIL
[URL: Setting <http://example.net/>.host = '[::1.2.3.\]']
expected: FAIL
[<a>: Setting <http://example.net/>.host = '[::1.2.3.\]']
expected: FAIL
[<area>: Setting <http://example.net/>.host = '[::1.2.3.\]']
expected: FAIL
[URL: Setting <http://example.net/>.host = '[::1.2.\]']
expected: FAIL
[<a>: Setting <http://example.net/>.host = '[::1.2.\]']
expected: FAIL
[<area>: Setting <http://example.net/>.host = '[::1.2.\]']
expected: FAIL
[URL: Setting <http://example.net/>.host = '[::1.\]']
expected: FAIL
[<a>: Setting <http://example.net/>.host = '[::1.\]']
expected: FAIL
[<area>: Setting <http://example.net/>.host = '[::1.\]']
expected: FAIL
@ -648,39 +624,15 @@
[<area>: Setting <http://example.net/>.hostname = '[google.com\]' Broken IPv6]
expected: FAIL
[URL: Setting <http://example.net/>.hostname = '[::1.2.3.4x\]']
expected: FAIL
[<a>: Setting <http://example.net/>.hostname = '[::1.2.3.4x\]']
expected: FAIL
[<area>: Setting <http://example.net/>.hostname = '[::1.2.3.4x\]']
expected: FAIL
[URL: Setting <http://example.net/>.hostname = '[::1.2.3.\]']
expected: FAIL
[<a>: Setting <http://example.net/>.hostname = '[::1.2.3.\]']
expected: FAIL
[<area>: Setting <http://example.net/>.hostname = '[::1.2.3.\]']
expected: FAIL
[URL: Setting <http://example.net/>.hostname = '[::1.2.\]']
expected: FAIL
[<a>: Setting <http://example.net/>.hostname = '[::1.2.\]']
expected: FAIL
[<area>: Setting <http://example.net/>.hostname = '[::1.2.\]']
expected: FAIL
[URL: Setting <http://example.net/>.hostname = '[::1.\]']
expected: FAIL
[<a>: Setting <http://example.net/>.hostname = '[::1.\]']
expected: FAIL
[<area>: Setting <http://example.net/>.hostname = '[::1.\]']
expected: FAIL