2020-03-23 03:08:41 +01:00
|
|
|
// ██████╗ █████╗ ███████╗███████╗██╗███╗ ██╗ ██████╗
|
|
|
|
// ██╔══██╗██╔══██╗██╔════╝██╔════╝██║████╗ ██║██╔════╝
|
|
|
|
// ██████╔╝███████║███████╗███████╗██║██╔██╗ ██║██║ ███╗
|
|
|
|
// ██╔═══╝ ██╔══██║╚════██║╚════██║██║██║╚██╗██║██║ ██║
|
|
|
|
// ██║ ██║ ██║███████║███████║██║██║ ╚████║╚██████╔╝
|
|
|
|
// ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝╚═╝ ╚═══╝ ╚═════╝
|
|
|
|
|
2020-05-23 09:49:04 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
mod passing {
|
2021-03-11 23:44:02 +01:00
|
|
|
use reqwest::Url;
|
|
|
|
|
2021-10-17 09:16:37 +02:00
|
|
|
use monolith::url;
|
2020-05-23 09:49:04 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_text_html_base64() {
|
2021-06-08 14:30:15 +02:00
|
|
|
let (media_type, charset, data) = url::parse_data_url(&Url::parse("data:text/html;base64,V29yayBleHBhbmRzIHNvIGFzIHRvIGZpbGwgdGhlIHRpbWUgYXZhaWxhYmxlIGZvciBpdHMgY29tcGxldGlvbg==").unwrap());
|
2020-05-23 09:49:04 +02:00
|
|
|
|
|
|
|
assert_eq!(media_type, "text/html");
|
2021-06-08 14:30:15 +02:00
|
|
|
assert_eq!(charset, "US-ASCII");
|
2020-05-23 09:49:04 +02:00
|
|
|
assert_eq!(
|
|
|
|
String::from_utf8_lossy(&data),
|
|
|
|
"Work expands so as to fill the time available for its completion"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_text_html_utf8() {
|
2021-06-08 14:30:15 +02:00
|
|
|
let (media_type, charset, data) = url::parse_data_url(
|
|
|
|
&Url::parse("data:text/html;charset=utf8,Work expands so as to fill the time available for its completion").unwrap(),
|
2020-05-23 09:49:04 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(media_type, "text/html");
|
2021-06-08 14:30:15 +02:00
|
|
|
assert_eq!(charset, "utf8");
|
2020-05-23 09:49:04 +02:00
|
|
|
assert_eq!(
|
|
|
|
String::from_utf8_lossy(&data),
|
|
|
|
"Work expands so as to fill the time available for its completion"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_text_html_plaintext() {
|
2021-06-08 14:30:15 +02:00
|
|
|
let (media_type, charset, data) = url::parse_data_url(
|
2021-03-11 23:44:02 +01:00
|
|
|
&Url::parse(
|
|
|
|
"data:text/html,Work expands so as to fill the time available for its completion",
|
|
|
|
)
|
|
|
|
.unwrap(),
|
2020-05-23 09:49:04 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(media_type, "text/html");
|
2021-06-08 14:30:15 +02:00
|
|
|
assert_eq!(charset, "US-ASCII");
|
2020-05-23 09:49:04 +02:00
|
|
|
assert_eq!(
|
|
|
|
String::from_utf8_lossy(&data),
|
|
|
|
"Work expands so as to fill the time available for its completion"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_text_css_url_encoded() {
|
2021-06-08 14:30:15 +02:00
|
|
|
let (media_type, charset, data) =
|
2021-03-11 23:44:02 +01:00
|
|
|
url::parse_data_url(&Url::parse("data:text/css,div{background-color:%23000}").unwrap());
|
2020-05-23 09:49:04 +02:00
|
|
|
|
|
|
|
assert_eq!(media_type, "text/css");
|
2021-06-08 14:30:15 +02:00
|
|
|
assert_eq!(charset, "US-ASCII");
|
2020-05-23 09:49:04 +02:00
|
|
|
assert_eq!(String::from_utf8_lossy(&data), "div{background-color:#000}");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_no_media_type_base64() {
|
2021-06-08 14:30:15 +02:00
|
|
|
let (media_type, charset, data) =
|
|
|
|
url::parse_data_url(&Url::parse("data:;base64,dGVzdA==").unwrap());
|
2020-05-23 09:49:04 +02:00
|
|
|
|
2021-06-08 14:30:15 +02:00
|
|
|
assert_eq!(media_type, "text/plain");
|
|
|
|
assert_eq!(charset, "US-ASCII");
|
2020-05-23 09:49:04 +02:00
|
|
|
assert_eq!(String::from_utf8_lossy(&data), "test");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_no_media_type_no_encoding() {
|
2021-06-08 14:30:15 +02:00
|
|
|
let (media_type, charset, data) =
|
|
|
|
url::parse_data_url(&Url::parse("data:;,test%20test").unwrap());
|
2020-05-23 09:49:04 +02:00
|
|
|
|
2021-06-08 14:30:15 +02:00
|
|
|
assert_eq!(media_type, "text/plain");
|
|
|
|
assert_eq!(charset, "US-ASCII");
|
2020-05-23 09:49:04 +02:00
|
|
|
assert_eq!(String::from_utf8_lossy(&data), "test test");
|
|
|
|
}
|
2020-04-10 02:27:07 +02:00
|
|
|
}
|
|
|
|
|
2020-03-23 03:08:41 +01:00
|
|
|
// ███████╗ █████╗ ██╗██╗ ██╗███╗ ██╗ ██████╗
|
|
|
|
// ██╔════╝██╔══██╗██║██║ ██║████╗ ██║██╔════╝
|
|
|
|
// █████╗ ███████║██║██║ ██║██╔██╗ ██║██║ ███╗
|
|
|
|
// ██╔══╝ ██╔══██║██║██║ ██║██║╚██╗██║██║ ██║
|
|
|
|
// ██║ ██║ ██║██║███████╗██║██║ ╚████║╚██████╔╝
|
|
|
|
// ╚═╝ ╚═╝ ╚═╝╚═╝╚══════╝╚═╝╚═╝ ╚═══╝ ╚═════╝
|
|
|
|
|
2020-05-23 09:49:04 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
mod failing {
|
2021-03-11 23:44:02 +01:00
|
|
|
use reqwest::Url;
|
|
|
|
|
2021-10-17 09:16:37 +02:00
|
|
|
use monolith::url;
|
2020-05-23 09:49:04 +02:00
|
|
|
|
|
|
|
#[test]
|
2021-03-11 23:44:02 +01:00
|
|
|
fn empty_data_url() {
|
2021-06-08 14:30:15 +02:00
|
|
|
let (media_type, charset, data) = url::parse_data_url(&Url::parse("data:,").unwrap());
|
2020-04-10 11:06:07 +02:00
|
|
|
|
2021-06-08 14:30:15 +02:00
|
|
|
assert_eq!(media_type, "text/plain");
|
|
|
|
assert_eq!(charset, "US-ASCII");
|
2020-05-23 09:49:04 +02:00
|
|
|
assert_eq!(String::from_utf8_lossy(&data), "");
|
|
|
|
}
|
2020-03-23 03:08:41 +01:00
|
|
|
}
|