commit
1480b20cb6
2 changed files with 8 additions and 10 deletions
|
@ -13,7 +13,7 @@ pub fn is_url(path: &str) -> bool {
|
|||
}
|
||||
|
||||
pub fn resolve_url(from: &str, to: &str) -> Result<String, ParseError> {
|
||||
let mut result = "".to_string();
|
||||
let mut result = String::new();
|
||||
|
||||
if is_url(to) { // (anything, http://site.com/css/main.css)
|
||||
result = to.to_string();
|
||||
|
@ -51,9 +51,9 @@ pub fn resolve_url(from: &str, to: &str) -> Result<String, ParseError> {
|
|||
}
|
||||
|
||||
pub fn url_is_data(url: &str) -> Result<bool, String> {
|
||||
match Url::parse(&url) {
|
||||
match Url::parse(url) {
|
||||
Ok(parsed_url) => Ok(parsed_url.scheme() == "data"),
|
||||
Err(err) => return Err(format!("{}", err.to_string())),
|
||||
Err(err) => return Err(format!("{}", err)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
12
src/utils.rs
12
src/utils.rs
|
@ -17,12 +17,7 @@ pub fn data_to_dataurl(mime: &str, data: &[u8]) -> String {
|
|||
}
|
||||
|
||||
fn detect_mimetype(data: &[u8]) -> String {
|
||||
let detected_mimetype = data.sniff_mime_type();
|
||||
if detected_mimetype != None {
|
||||
detected_mimetype.unwrap().to_string()
|
||||
} else {
|
||||
"".to_string()
|
||||
}
|
||||
data.sniff_mime_type().unwrap_or("").to_string()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -34,6 +29,9 @@ mod tests {
|
|||
let mime = "application/javascript";
|
||||
let data = "var word = 'hello';\nalert(word);\n";
|
||||
let datauri = data_to_dataurl(mime, data.as_bytes());
|
||||
assert_eq!(&datauri, "data:application/javascript;base64,dmFyIHdvcmQgPSAnaGVsbG8nOwphbGVydCh3b3JkKTsK");
|
||||
assert_eq!(
|
||||
&datauri,
|
||||
"data:application/javascript;base64,dmFyIHdvcmQgPSAnaGVsbG8nOwphbGVydCh3b3JkKTsK"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue