aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2017-10-31 17:30:01 +0100
committerSimon Sapin <simon.sapin@exyr.org>2017-10-31 19:08:26 +0100
commita3ac21d23d3fc717334bf4c8df0f9b1c613cbaaa (patch)
treec73db7dcfa88d39d4fd4144d8ec443dbe8d64aee /components/script
parent43a4f016471d1e1d6b4072f9dd8cf3b8f9dfe48c (diff)
downloadservo-a3ac21d23d3fc717334bf4c8df0f9b1c613cbaaa.tar.gz
servo-a3ac21d23d3fc717334bf4c8df0f9b1c613cbaaa.zip
Use the url crate without its query_encoding feature
Diffstat (limited to 'components/script')
-rw-r--r--components/script/Cargo.toml2
-rwxr-xr-xcomponents/script/dom/htmlformelement.rs27
-rw-r--r--components/script/dom/urlsearchparams.rs6
-rw-r--r--components/script/dom/xmlhttprequest.rs3
4 files changed, 22 insertions, 16 deletions
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<FormDatum>, 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<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
+ }
+
/// [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<EncodingRef>) -> 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<u8>, Option<DOMString>) {
- // 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")))
}
}