aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmlformelement.rs
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2017-10-31 19:06:34 +0100
committerSimon Sapin <simon.sapin@exyr.org>2017-11-01 10:16:11 +0100
commita3971eb686503641a0e9cc64f4844a6abdd5cda1 (patch)
treef443a6e5182bfb8c2b09afae3bbb95c4df3a7f0e /components/script/dom/htmlformelement.rs
parent3c36a36cc942a6cce52d4575ad6c26bbde6e4bd7 (diff)
downloadservo-a3971eb686503641a0e9cc64f4844a6abdd5cda1.tar.gz
servo-a3971eb686503641a0e9cc64f4844a6abdd5cda1.zip
Replace rust-encoding with encoding-rs
Diffstat (limited to 'components/script/dom/htmlformelement.rs')
-rwxr-xr-xcomponents/script/dom/htmlformelement.rs29
1 files changed, 12 insertions, 17 deletions
diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs
index 18c8a9bf348..e4ce6dfef43 100755
--- a/components/script/dom/htmlformelement.rs
+++ b/components/script/dom/htmlformelement.rs
@@ -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() {