aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathieu Rheaume <mathieu@codingrhemes.com>2015-09-12 19:59:20 -0400
committerMathieu Rheaume <mathieu@codingrhemes.com>2015-09-12 19:59:20 -0400
commitcc44448b0922f184b22cdb2ecc29af37496c52b0 (patch)
tree567f59ede858a6228aa76ab322fe8e8134ed3cbd
parent68a088bef60365cbd3cd8ba4dcf42f049129d810 (diff)
downloadservo-cc44448b0922f184b22cdb2ecc29af37496c52b0.tar.gz
servo-cc44448b0922f184b22cdb2ecc29af37496c52b0.zip
Fix BinaryOrPLaintextClassifier bug with utf16-be & utf16-le and correct tests
-rw-r--r--components/net/mime_classifier.rs5
-rw-r--r--tests/unit/net/mime_classifier.rs14
2 files changed, 9 insertions, 10 deletions
diff --git a/components/net/mime_classifier.rs b/components/net/mime_classifier.rs
index ab7a9686755..a9eac63c8cf 100644
--- a/components/net/mime_classifier.rs
+++ b/components/net/mime_classifier.rs
@@ -39,7 +39,6 @@ impl MIMEClassifier {
apache_bug_flag: ApacheBugFlag,
supplied_type: &Option<(String, String)>,
data: &[u8]) -> Option<(String, String)> {
-
match *supplied_type {
None => self.sniff_unknown_type(no_sniff_flag, data),
Some((ref media_type, ref media_subtype)) => {
@@ -279,8 +278,8 @@ struct BinaryOrPlaintextClassifier;
impl BinaryOrPlaintextClassifier {
fn classify_impl(&self, data: &[u8]) -> (&'static str, &'static str) {
- if data == &[0xFFu8, 0xFEu8] ||
- data == &[0xFEu8, 0xFFu8] ||
+ if data.starts_with(&[0xFFu8, 0xFEu8]) ||
+ data.starts_with(&[0xFEu8, 0xFFu8]) ||
data.starts_with(&[0xEFu8, 0xBBu8, 0xBFu8])
{
("text", "plain")
diff --git a/tests/unit/net/mime_classifier.rs b/tests/unit/net/mime_classifier.rs
index 02561ae5ab2..b8538dc9ab8 100644
--- a/tests/unit/net/mime_classifier.rs
+++ b/tests/unit/net/mime_classifier.rs
@@ -494,7 +494,7 @@ fn test_sniff_utf_8_bom_with_apache_flag_on() {
test_sniff_with_flags(&PathBuf::from("text/plain/utf8bom.txt"),
"text",
"plain",
- None,
+ Some(("dummy", "text")),
NoSniffFlag::OFF,
ApacheBugFlag::ON);
}
@@ -504,7 +504,7 @@ fn test_sniff_utf_16be_bom_with_apache_flag_on() {
test_sniff_with_flags(&PathBuf::from("text/plain/utf16bebom.txt"),
"text",
"plain",
- None,
+ Some(("dummy", "text")),
NoSniffFlag::OFF,
ApacheBugFlag::ON);
}
@@ -514,7 +514,7 @@ fn test_sniff_utf_16le_bom_with_apache_flag_on() {
test_sniff_with_flags(&PathBuf::from("text/plain/utf16lebom.txt"),
"text",
"plain",
- None,
+ Some(("dummy", "text")),
NoSniffFlag::OFF,
ApacheBugFlag::ON);
}
@@ -524,7 +524,7 @@ fn test_sniff_octet_stream_apache_flag_on() {
test_sniff_with_flags(&PathBuf::from("unknown/binary_file"),
"application",
"octet-stream",
- None,
+ Some(("dummy", "binary")),
NoSniffFlag::OFF,
ApacheBugFlag::ON);
}
@@ -532,9 +532,9 @@ fn test_sniff_octet_stream_apache_flag_on() {
#[test]
fn test_sniff_mp4_video_apache_flag_on() {
test_sniff_with_flags(&PathBuf::from("video/mp4/test.mp4"),
- "video",
- "mp4",
- Some("video", "mp4"),
+ "application",
+ "octet-stream",
+ Some(("video", "mp4")),
NoSniffFlag::OFF,
ApacheBugFlag::ON);
}