aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmlformelement.rs
diff options
context:
space:
mode:
authorZhen Zhang <izgzhen@gmail.com>2016-05-17 12:52:35 +0800
committerZhen Zhang <izgzhen@gmail.com>2016-06-01 09:47:07 +0800
commit43ad4ba5857dbcd1a31aaf7e441c5cfe4fe1b84f (patch)
treeef221985dfe1d3ed54e7a2af31903d8b1dbf40e4 /components/script/dom/htmlformelement.rs
parentd53507f747f7122dc520f5e4a374ee1ad955aa5d (diff)
downloadservo-43ad4ba5857dbcd1a31aaf7e441c5cfe4fe1b84f.tar.gz
servo-43ad4ba5857dbcd1a31aaf7e441c5cfe4fe1b84f.zip
Add file backend support for Blob and related
Changes include: - Add BlobImpl to Blob, and related caching mechanism - Expose ResourceThreads to document_loader, workerglobalscope, worker, and global - Fix encode_multipart_form_data - Other small fixes to accommodate the above changes
Diffstat (limited to 'components/script/dom/htmlformelement.rs')
-rw-r--r--components/script/dom/htmlformelement.rs14
1 files changed, 10 insertions, 4 deletions
diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs
index 50490ec879f..7f54fc7842b 100644
--- a/components/script/dom/htmlformelement.rs
+++ b/components/script/dom/htmlformelement.rs
@@ -40,6 +40,7 @@ use dom::window::Window;
use encoding::EncodingRef;
use encoding::all::UTF_8;
use encoding::label::encoding_from_whatwg_label;
+use encoding::types::DecoderTrap;
use hyper::header::{Charset, ContentDisposition, ContentType, DispositionParam, DispositionType};
use hyper::method::Method;
use msg::constellation_msg::{LoadData, PipelineId};
@@ -47,7 +48,6 @@ use rand::random;
use script_thread::{MainThreadScriptMsg, Runnable};
use std::borrow::ToOwned;
use std::cell::Cell;
-use std::str::from_utf8;
use std::sync::mpsc::Sender;
use string_cache::Atom;
use task_source::dom_manipulation::DOMManipulationTask;
@@ -281,7 +281,7 @@ impl HTMLFormElement {
let encoding = encoding.unwrap_or(self.pick_encoding());
// Step 3
- let charset = &*encoding.whatwg_name().unwrap();
+ let charset = &*encoding.whatwg_name().unwrap_or("UTF-8");
// Step 4
for entry in form_data.iter_mut() {
@@ -309,12 +309,18 @@ impl HTMLFormElement {
DispositionParam::Filename(Charset::Ext(String::from(charset.clone())),
None,
f.name().clone().into()));
- let content_type = ContentType(f.upcast::<Blob>().Type().parse().unwrap());
+ // https://tools.ietf.org/html/rfc7578#section-4.4
+ let content_type = ContentType(f.upcast::<Blob>().Type()
+ .parse().unwrap_or(mime!(Text / Plain)));
result.push_str(&*format!("Content-Disposition: {}\r\n{}\r\n\r\n",
content_disposition,
content_type));
- result.push_str(from_utf8(&f.upcast::<Blob>().get_data().get_bytes()).unwrap());
+ let slice = f.upcast::<Blob>().get_slice_or_empty();
+
+ let decoded = encoding.decode(&slice.get_bytes(), DecoderTrap::Replace)
+ .expect("Invalid encoding in file");
+ result.push_str(&decoded);
}
}
}