diff --git a/Cargo.lock b/Cargo.lock index d122c3ee230..761376ab838 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -334,7 +334,7 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-normalization 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1302,7 +1302,7 @@ dependencies = [ "traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1335,12 +1335,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "idna" -version = "0.1.2" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-bidi 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-normalization 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1752,7 +1752,7 @@ dependencies = [ "smallbitvec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "string_cache 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "webrender_api 0.53.1 (git+https://github.com/servo/webrender)", "xml5ever 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1983,7 +1983,7 @@ dependencies = [ "time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", "tinyfiledialogs 2.5.9 (registry+https://github.com/rust-lang/crates.io-index)", "unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "uuid 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "webrender_api 0.53.1 (git+https://github.com/servo/webrender)", ] @@ -2019,7 +2019,7 @@ dependencies = [ "servo_url 0.0.1", "time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", "unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2040,7 +2040,7 @@ dependencies = [ "serde 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", "servo_config 0.0.1", "servo_url 0.0.1", - "url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "uuid 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "webrender_api 0.53.1 (git+https://github.com/servo/webrender)", ] @@ -2664,7 +2664,7 @@ dependencies = [ "time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", "tinyfiledialogs 2.5.9 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-segmentation 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "utf-8 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "uuid 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "webrender_api 0.53.1 (git+https://github.com/servo/webrender)", @@ -2743,7 +2743,7 @@ dependencies = [ "servo_url 0.0.1", "style_traits 0.0.1", "time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "webrender_api 0.53.1 (git+https://github.com/servo/webrender)", "webvr_traits 0.0.1", ] @@ -2939,7 +2939,7 @@ dependencies = [ "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)", "unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2983,7 +2983,7 @@ dependencies = [ "serde 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", "servo_geometry 0.0.1", "servo_url 0.0.1", - "url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "xdg 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3037,7 +3037,7 @@ dependencies = [ "malloc_size_of_derive 0.0.1", "serde 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", "servo_rand 0.0.1", - "url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "url_serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "uuid 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3465,7 +3465,7 @@ dependencies = [ [[package]] name = "unicode-normalization" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -3501,11 +3501,10 @@ dependencies = [ [[package]] name = "url" -version = "1.5.1" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", - "idna 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "percent-encoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3516,7 +3515,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "serde 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3607,7 +3606,7 @@ dependencies = [ "script_traits 0.0.1", "servo_config 0.0.1", "servo_url 0.0.1", - "url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "uuid 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "webdriver 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3705,7 +3704,7 @@ dependencies = [ "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", "sha1 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3903,7 +3902,7 @@ dependencies = [ "checksum hyper-openssl 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "85a372eb692590b3fe014c196c30f9f52d4c42f58cd49dd94caeee1593c9cc37" "checksum hyper_serde 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cbe43f514f80494e9329c9fc47d61b85b167d245685424637a0f4a409177e444" "checksum ident_case 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c9826188e666f2ed92071d2dadef6edc430b11b158b5b2b3f4babbcc891eaaa" -"checksum idna 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2233d4940b1f19f0418c158509cd7396b8d70a5db5705ce410914dc8fa603b37" +"checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d" "checksum image 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e70634e5518ee89975b43c4bbd1667c4012c0313392aa2dfa2db5563c28e34c2" "checksum immeta 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0b9260463a221bfe3f02100c56e2d14c050d5ffe7e44a43d0a1b2b1f2b523502" "checksum inflate 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "10ec05638adf7c5c788bc0cfa608cd479a13572beda20feb4898fe1d85d2c64b" @@ -4055,13 +4054,13 @@ dependencies = [ "checksum typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" "checksum unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "13a5906ca2b98c799f4b1ab4557b76367ebd6ae5ef14930ec841c74aed5f3764" "checksum unicode-bidi 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a6a2c4e3710edd365cd7e78383153ed739fa31af19f9172f72d3575060f5a43a" -"checksum unicode-normalization 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "e28fa37426fceeb5cf8f41ee273faa7c82c47dc8fba5853402841e665fcd86ff" +"checksum unicode-normalization 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "51ccda9ef9efa3f7ef5d91e8f9b83bbe6955f9bf86aec89d5cce2c874625920f" "checksum unicode-script 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e5430ae21ef212551680d0021fc7dbd936e8b268c5ea8fdae8814e0b2496d80f" "checksum unicode-segmentation 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a8083c594e02b8ae1654ae26f0ade5158b119bd88ad0e8227a5d8fcd72407946" "checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f" "checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" "checksum unreachable 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2ae5ddb18e1c92664717616dd9549dde73f539f01bd7b77c2edb2446bdff91" -"checksum url 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eeb819346883532a271eb626deb43c4a1bb4c4dd47c519bd78137c3e72a4fe27" +"checksum url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa35e768d4daf1d85733418a49fb42e10d7f633e394fccab4ab7aba897053fe2" "checksum url_serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "74e7d099f1ee52f823d4bdd60c93c3602043c728f5db3b97bdb548467f7bddea" "checksum user32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4ef4711d107b21b410a3a974b1204d9accc8b10dad75d8324b5d755de1617d47" "checksum utf-8 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b6f923c601c7ac48ef1d66f7d5b5b2d9a7ba9c51333ab75a3ddf8d0309185a56" diff --git a/components/script/Cargo.toml b/components/script/Cargo.toml index 1056eba1127..c736ba19c8e 100644 --- a/components/script/Cargo.toml +++ b/components/script/Cargo.toml @@ -90,7 +90,7 @@ style_traits = {path = "../style_traits"} swapper = "0.1" time = "0.1.12" unicode-segmentation = "1.1.0" -url = {version = "1.2", features = ["query_encoding"]} +url = "1.6" utf-8 = "0.7" uuid = {version = "0.5", features = ["v4"]} xml5ever = {version = "0.11"} diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs index 9e0c32aa057..18c8a9bf348 100755 --- a/components/script/dom/htmlformelement.rs +++ b/components/script/dom/htmlformelement.rs @@ -42,7 +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; +use encoding::{EncodingRef, EncoderTrap}; use encoding::all::UTF_8; use encoding::label::encoding_from_whatwg_label; use html5ever::{LocalName, Prefix}; @@ -56,6 +56,8 @@ use std::cell::Cell; use style::attr::AttrValue; use style::str::split_html_space_chars; use task_source::TaskSource; +use url::UrlQuery; +use url::form_urlencoded::Serializer; #[derive(Clone, Copy, JSTraceable, MallocSizeOf, PartialEq)] pub struct GenerationId(u32); @@ -378,10 +380,8 @@ impl HTMLFormElement { fn mutate_action_url(&self, form_data: &mut Vec, mut load_data: LoadData, encoding: EncodingRef) { let charset = &*encoding.whatwg_name().unwrap(); - load_data.url - .as_mut_url() - .query_pairs_mut().clear() - .encoding_override(Some(self.pick_encoding())) + self.set_encoding_override(load_data.url.as_mut_url().query_pairs_mut()) + .clear() .extend_pairs(form_data.into_iter() .map(|field| (field.name.clone(), field.replace_value(charset)))); @@ -397,10 +397,8 @@ impl HTMLFormElement { let charset = &*encoding.whatwg_name().unwrap(); load_data.headers.set(ContentType::form_url_encoded()); - load_data.url - .as_mut_url() - .query_pairs_mut().clear() - .encoding_override(Some(self.pick_encoding())) + self.set_encoding_override(load_data.url.as_mut_url().query_pairs_mut()) + .clear() .extend_pairs(form_data.into_iter() .map(|field| (field.name.clone(), field.replace_value(charset)))); @@ -421,6 +419,17 @@ impl HTMLFormElement { self.plan_to_navigate(load_data); } + fn set_encoding_override<'a>(&self, mut serializer: Serializer>) + -> Serializer> { + let encoding = self.pick_encoding(); + if encoding.name() != "utf-8" { + serializer.custom_encoding_override(move |s| { + encoding.encode(s, EncoderTrap::NcrEscape).unwrap().into() + }); + } + serializer + } + /// [Planned navigation](https://html.spec.whatwg.org/multipage/#planned-navigation) fn plan_to_navigate(&self, load_data: LoadData) { let window = window_from_node(self); diff --git a/components/script/dom/urlsearchparams.rs b/components/script/dom/urlsearchparams.rs index a5519894c54..a3a297a5f46 100644 --- a/components/script/dom/urlsearchparams.rs +++ b/components/script/dom/urlsearchparams.rs @@ -15,7 +15,6 @@ use dom::bindings::weakref::MutableWeakRef; use dom::globalscope::GlobalScope; use dom::url::URL; use dom_struct::dom_struct; -use encoding::types::EncodingRef; use url::form_urlencoded; // https://url.spec.whatwg.org/#interface-urlsearchparams @@ -140,17 +139,16 @@ impl URLSearchParamsMethods for URLSearchParams { // https://url.spec.whatwg.org/#stringification-behavior fn Stringifier(&self) -> DOMString { - DOMString::from(self.serialize(None)) + DOMString::from(self.serialize_utf8()) } } impl URLSearchParams { // https://url.spec.whatwg.org/#concept-urlencoded-serializer - pub fn serialize(&self, encoding: Option) -> String { + pub fn serialize_utf8(&self) -> String { let list = self.list.borrow(); form_urlencoded::Serializer::new(String::new()) - .encoding_override(encoding) .extend_pairs(&*list) .finish() } diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs index 580189f5768..c7745546717 100644 --- a/components/script/dom/xmlhttprequest.rs +++ b/components/script/dom/xmlhttprequest.rs @@ -1386,8 +1386,7 @@ impl Extractable for FormData { impl Extractable for URLSearchParams { fn extract(&self) -> (Vec, Option) { - // Default encoding is UTF-8. - (self.serialize(None).into_bytes(), + (self.serialize_utf8().into_bytes(), Some(DOMString::from("application/x-www-form-urlencoded;charset=UTF-8"))) } }