aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/blob.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/blob.rs')
-rw-r--r--components/script/dom/blob.rs44
1 files changed, 19 insertions, 25 deletions
diff --git a/components/script/dom/blob.rs b/components/script/dom/blob.rs
index b2bce4f2ece..f63e66e3b7b 100644
--- a/components/script/dom/blob.rs
+++ b/components/script/dom/blob.rs
@@ -17,7 +17,6 @@ use ipc_channel::ipc;
use net_traits::IpcSend;
use net_traits::blob_url_store::{BlobBuf, get_blob_origin};
use net_traits::filemanager_thread::{FileManagerThreadMsg, SelectedFileId, RelativePos};
-use std::ascii::AsciiExt;
use std::cell::Cell;
use std::ops::Index;
use std::path::PathBuf;
@@ -86,7 +85,9 @@ impl Blob {
Blob {
reflector_: Reflector::new(),
blob_impl: DOMRefCell::new(blob_impl),
- typeString: typeString,
+ // NOTE: Guarding the format correctness here,
+ // https://w3c.github.io/FileAPI/#dfn-type
+ typeString: normalize_type_string(&typeString),
isClosed_: Cell::new(false),
}
}
@@ -135,7 +136,7 @@ impl Blob {
}
};
- Ok(Blob::new(global, BlobImpl::new_from_bytes(bytes), blobPropertyBag.get_typestring()))
+ Ok(Blob::new(global, BlobImpl::new_from_bytes(bytes), blobPropertyBag.type_.to_string()))
}
/// Get a slice to inner data, this might incur synchronous read and caching
@@ -332,20 +333,8 @@ impl BlobMethods for Blob {
end: Option<i64>,
contentType: Option<DOMString>)
-> Root<Blob> {
- let relativeContentType = match contentType {
- None => DOMString::new(),
- Some(mut str) => {
- if is_ascii_printable(&str) {
- str.make_ascii_lowercase();
- str
- } else {
- DOMString::new()
- }
- }
- };
-
let rel_pos = RelativePos::from_opts(start, end);
- Blob::new_sliced(self, rel_pos, relativeContentType)
+ Blob::new_sliced(self, rel_pos, contentType.unwrap_or(DOMString::from("")))
}
// https://w3c.github.io/FileAPI/#dfn-isClosed
@@ -368,15 +357,20 @@ impl BlobMethods for Blob {
}
}
-impl BlobBinding::BlobPropertyBag {
- /// Get the normalized inner type string
- /// https://w3c.github.io/FileAPI/#dfn-type
- pub fn get_typestring(&self) -> String {
- if is_ascii_printable(&self.type_) {
- self.type_.to_lowercase()
- } else {
- "".to_string()
- }
+/// Get the normalized, MIME-parsable type string
+/// https://w3c.github.io/FileAPI/#dfn-type
+/// XXX: We will relax the restriction here,
+/// since the spec has some problem over this part.
+/// see https://github.com/w3c/FileAPI/issues/43
+fn normalize_type_string(s: &str) -> String {
+ if is_ascii_printable(s) {
+ let s_lower = s.to_lowercase();
+ // match s_lower.parse() as Result<Mime, ()> {
+ // Ok(_) => s_lower,
+ // Err(_) => "".to_string()
+ s_lower
+ } else {
+ "".to_string()
}
}