diff options
author | Manish Goregaokar <manishsmail@gmail.com> | 2020-01-06 13:59:54 +0530 |
---|---|---|
committer | Manish Goregaokar <manishsmail@gmail.com> | 2020-01-06 15:47:07 +0530 |
commit | 508bfbd0da53b0badf76e07c6286d6bd4e29900e (patch) | |
tree | faa5c4a5bf6df55c90d50e399e81b741dde9070b | |
parent | be917ae9ef011a0b1ed4ea512f98a30b9d59b769 (diff) | |
download | servo-508bfbd0da53b0badf76e07c6286d6bd4e29900e.tar.gz servo-508bfbd0da53b0badf76e07c6286d6bd4e29900e.zip |
Fix module script MIME check to not include params
Also makes it error when there is no MIME type available.
-rw-r--r-- | components/script/script_module.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/components/script/script_module.rs b/components/script/script_module.rs index 6a2d30d72c5..4bb60f5a233 100644 --- a/components/script/script_module.rs +++ b/components/script/script_module.rs @@ -931,9 +931,18 @@ impl FetchResponseListener for ModuleContext { let meta = self.metadata.take().unwrap(); if let Some(content_type) = meta.content_type.map(Serde::into_inner) { - if !SCRIPT_JS_MIMES.contains(&content_type.to_string().as_str()) { - return Err(NetworkError::Internal("Invalid MIME type".to_owned())); + let c = content_type.to_string(); + // The MIME crate includes params (e.g. charset=utf8) in the to_string + // https://github.com/hyperium/mime/issues/120 + if let Some(ty) = c.split(';').next() { + if !SCRIPT_JS_MIMES.contains(&ty) { + return Err(NetworkError::Internal(format!("Invalid MIME type: {}", ty))); + } + } else { + return Err(NetworkError::Internal("Empty MIME type".into())); } + } else { + return Err(NetworkError::Internal("No MIME type".into())); } // Step 10. |