cleanup
This commit is contained in:
parent
58d5ac7e75
commit
480acf515f
3 changed files with 16 additions and 11 deletions
|
@ -309,7 +309,6 @@ pub fn mime_extension_lookup(essence: String) -> Option<Vec<String>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let essence = essence;
|
|
||||||
let mut exts = mime_guess::get_mime_extensions_str(essence.as_str());
|
let mut exts = mime_guess::get_mime_extensions_str(essence.as_str());
|
||||||
if exts.is_none() {
|
if exts.is_none() {
|
||||||
// no matches :c
|
// no matches :c
|
||||||
|
@ -363,9 +362,13 @@ pub fn mime_extension_lookup(essence: String) -> Option<Vec<String>> {
|
||||||
]
|
]
|
||||||
.concat()
|
.concat()
|
||||||
} else if essence == "application/x-ms-dos-executable" {
|
} else if essence == "application/x-ms-dos-executable" {
|
||||||
// both .dll and .exe files are given the same mime type... but you definitely don't want to rename one to the
|
// .dll, .exe, and .scr files are given the same mime type... but you definitely don't want to rename one to the
|
||||||
// other!
|
// other!
|
||||||
[vec![String::from("dll"), String::from("exe")], possible_exts].concat()
|
[
|
||||||
|
vec![String::from("dll"), String::from("exe"), String::from("scr")],
|
||||||
|
possible_exts,
|
||||||
|
]
|
||||||
|
.concat()
|
||||||
} else {
|
} else {
|
||||||
possible_exts
|
possible_exts
|
||||||
})
|
})
|
||||||
|
|
|
@ -11,6 +11,7 @@ use fif::files::{mime_extension_lookup, scan_directory, scan_from_walkdir, BUF_S
|
||||||
use fif::findings::Findings;
|
use fif::findings::Findings;
|
||||||
use fif::formats::{Format, PowerShell, Shell};
|
use fif::formats::{Format, PowerShell, Shell};
|
||||||
use fif::mime_db::MimeDb;
|
use fif::mime_db::MimeDb;
|
||||||
|
use fif::utils::APPLICATION_ZIP;
|
||||||
use fif::{String, MIMEDB};
|
use fif::{String, MIMEDB};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use maplit::{btreeset, hashmap};
|
use maplit::{btreeset, hashmap};
|
||||||
|
@ -24,11 +25,6 @@ const PNG_BYTES: &[u8] = b"\x89\x50\x4E\x47\x0D\x0A\x1A\x0A";
|
||||||
const PDF_BYTES: &[u8] = b"%PDF-";
|
const PDF_BYTES: &[u8] = b"%PDF-";
|
||||||
const ZIP_BYTES: &[u8] = b"PK\x03\x04";
|
const ZIP_BYTES: &[u8] = b"PK\x03\x04";
|
||||||
|
|
||||||
fn application_zip() -> Mime {
|
|
||||||
use std::str::FromStr;
|
|
||||||
Mime::from_str("application/zip").unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
/// Ensure that `extension_from_path` successfully returns the extension from a set of paths.
|
/// Ensure that `extension_from_path` successfully returns the extension from a set of paths.
|
||||||
fn get_ext() {
|
fn get_ext() {
|
||||||
|
@ -52,7 +48,7 @@ fn detect_type() {
|
||||||
assert_eq!(MIMEDB.get_type(JPEG_BYTES), Some(IMAGE_JPEG));
|
assert_eq!(MIMEDB.get_type(JPEG_BYTES), Some(IMAGE_JPEG));
|
||||||
assert_eq!(MIMEDB.get_type(PNG_BYTES), Some(IMAGE_PNG));
|
assert_eq!(MIMEDB.get_type(PNG_BYTES), Some(IMAGE_PNG));
|
||||||
assert_eq!(MIMEDB.get_type(PDF_BYTES), Some(APPLICATION_PDF));
|
assert_eq!(MIMEDB.get_type(PDF_BYTES), Some(APPLICATION_PDF));
|
||||||
assert_eq!(MIMEDB.get_type(ZIP_BYTES), Some(application_zip()));
|
assert_eq!(MIMEDB.get_type(ZIP_BYTES), Some(APPLICATION_ZIP.clone()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -68,7 +64,7 @@ fn recommend_ext() {
|
||||||
assert!(mime_extension_lookup(APPLICATION_PDF.essence_str().into())
|
assert!(mime_extension_lookup(APPLICATION_PDF.essence_str().into())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.contains(&String::from("pdf")));
|
.contains(&String::from("pdf")));
|
||||||
assert!(mime_extension_lookup(application_zip().essence_str().into())
|
assert!(mime_extension_lookup(APPLICATION_ZIP.essence_str().into())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.contains(&String::from("zip")));
|
.contains(&String::from("zip")));
|
||||||
}
|
}
|
||||||
|
@ -178,7 +174,7 @@ fn simple_directory() {
|
||||||
"jpg" | "jpeg" => IMAGE_JPEG,
|
"jpg" | "jpeg" => IMAGE_JPEG,
|
||||||
"png" => IMAGE_PNG,
|
"png" => IMAGE_PNG,
|
||||||
"pdf" => APPLICATION_PDF,
|
"pdf" => APPLICATION_PDF,
|
||||||
"zip" => application_zip(),
|
"zip" => APPLICATION_ZIP.clone(),
|
||||||
_ => APPLICATION_OCTET_STREAM, // general "fallback" type
|
_ => APPLICATION_OCTET_STREAM, // general "fallback" type
|
||||||
},
|
},
|
||||||
"Incorrect MIME type detected - got {:?} for a {:?} file",
|
"Incorrect MIME type detected - got {:?} for a {:?} file",
|
||||||
|
|
|
@ -3,7 +3,10 @@
|
||||||
|
|
||||||
//! Various minor utilities.
|
//! Various minor utilities.
|
||||||
|
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use cfg_if::cfg_if;
|
use cfg_if::cfg_if;
|
||||||
|
use mime::Mime;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
use crate::String;
|
use crate::String;
|
||||||
|
@ -36,6 +39,9 @@ pub static CLAP_LONG_VERSION: Lazy<String> = Lazy::new(|| {
|
||||||
.into()
|
.into()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/// A [`Mime`] representing the "application/zip" mimetype.
|
||||||
|
pub static APPLICATION_ZIP: Lazy<Mime> = Lazy::new(|| Mime::from_str("application/zip").unwrap());
|
||||||
|
|
||||||
/// Returns the name of the target operating system with proper casing, like "Windows" or "macOS".
|
/// Returns the name of the target operating system with proper casing, like "Windows" or "macOS".
|
||||||
#[allow(clippy::option_map_unit_fn)]
|
#[allow(clippy::option_map_unit_fn)]
|
||||||
pub fn os_name() -> String {
|
pub fn os_name() -> String {
|
||||||
|
|
Loading…
Reference in a new issue