|
|
|
@ -1,7 +1,3 @@
|
|
|
|
|
use url::ParseError;
|
|
|
|
|
|
|
|
|
|
use crate::utils;
|
|
|
|
|
|
|
|
|
|
// ██████╗ █████╗ ███████╗███████╗██╗███╗ ██╗ ██████╗
|
|
|
|
|
// ██╔══██╗██╔══██╗██╔════╝██╔════╝██║████╗ ██║██╔════╝
|
|
|
|
|
// ██████╔╝███████║███████╗███████╗██║██╔██╗ ██║██║ ███╗
|
|
|
|
@ -9,9 +5,15 @@ use crate::utils;
|
|
|
|
|
// ██║ ██║ ██║███████║███████║██║██║ ╚████║╚██████╔╝
|
|
|
|
|
// ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝╚═╝ ╚═══╝ ╚═════╝
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod passing {
|
|
|
|
|
use crate::utils;
|
|
|
|
|
use url::ParseError;
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn passing_from_https_to_level_up_relative() -> Result<(), ParseError> {
|
|
|
|
|
let resolved_url = utils::resolve_url("https://www.kernel.org", "../category/signatures.html")?;
|
|
|
|
|
fn from_https_to_level_up_relative() -> Result<(), ParseError> {
|
|
|
|
|
let resolved_url =
|
|
|
|
|
utils::resolve_url("https://www.kernel.org", "../category/signatures.html")?;
|
|
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
|
resolved_url.as_str(),
|
|
|
|
@ -22,7 +24,7 @@ fn passing_from_https_to_level_up_relative() -> Result<(), ParseError> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn passing_from_just_filename_to_full_https_url() -> Result<(), ParseError> {
|
|
|
|
|
fn from_just_filename_to_full_https_url() -> Result<(), ParseError> {
|
|
|
|
|
let resolved_url = utils::resolve_url(
|
|
|
|
|
"saved_page.htm",
|
|
|
|
|
"https://www.kernel.org/category/signatures.html",
|
|
|
|
@ -37,7 +39,7 @@ fn passing_from_just_filename_to_full_https_url() -> Result<(), ParseError> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn passing_from_https_url_to_url_with_no_protocol() -> Result<(), ParseError> {
|
|
|
|
|
fn from_https_url_to_url_with_no_protocol() -> Result<(), ParseError> {
|
|
|
|
|
let resolved_url = utils::resolve_url(
|
|
|
|
|
"https://www.kernel.org",
|
|
|
|
|
"//www.kernel.org/theme/images/logos/tux.png",
|
|
|
|
@ -52,8 +54,8 @@ fn passing_from_https_url_to_url_with_no_protocol() -> Result<(), ParseError> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn passing_from_https_url_to_url_with_no_protocol_and_on_different_hostname(
|
|
|
|
|
) -> Result<(), ParseError> {
|
|
|
|
|
fn from_https_url_to_url_with_no_protocol_and_on_different_hostname() -> Result<(), ParseError>
|
|
|
|
|
{
|
|
|
|
|
let resolved_url = utils::resolve_url(
|
|
|
|
|
"https://www.kernel.org",
|
|
|
|
|
"//another-host.org/theme/images/logos/tux.png",
|
|
|
|
@ -68,7 +70,7 @@ fn passing_from_https_url_to_url_with_no_protocol_and_on_different_hostname(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn passing_from_https_url_to_relative_root_path() -> Result<(), ParseError> {
|
|
|
|
|
fn from_https_url_to_relative_root_path() -> Result<(), ParseError> {
|
|
|
|
|
let resolved_url = utils::resolve_url(
|
|
|
|
|
"https://www.kernel.org/category/signatures.html",
|
|
|
|
|
"/theme/images/logos/tux.png",
|
|
|
|
@ -83,7 +85,7 @@ fn passing_from_https_url_to_relative_root_path() -> Result<(), ParseError> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn passing_from_https_to_just_filename() -> Result<(), ParseError> {
|
|
|
|
|
fn from_https_to_just_filename() -> Result<(), ParseError> {
|
|
|
|
|
let resolved_url = utils::resolve_url(
|
|
|
|
|
"https://www.w3schools.com/html/html_iframe.asp",
|
|
|
|
|
"default.asp",
|
|
|
|
@ -98,7 +100,7 @@ fn passing_from_https_to_just_filename() -> Result<(), ParseError> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn passing_from_data_url_to_https() -> Result<(), ParseError> {
|
|
|
|
|
fn from_data_url_to_https() -> Result<(), ParseError> {
|
|
|
|
|
let resolved_url = utils::resolve_url(
|
|
|
|
|
"data:text/html;base64,V2VsY29tZSBUbyBUaGUgUGFydHksIDxiPlBhbDwvYj4h",
|
|
|
|
|
"https://www.kernel.org/category/signatures.html",
|
|
|
|
@ -113,7 +115,7 @@ fn passing_from_data_url_to_https() -> Result<(), ParseError> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn passing_from_data_url_to_data_url() -> Result<(), ParseError> {
|
|
|
|
|
fn from_data_url_to_data_url() -> Result<(), ParseError> {
|
|
|
|
|
let resolved_url = utils::resolve_url(
|
|
|
|
|
"data:text/html;base64,V2VsY29tZSBUbyBUaGUgUGFydHksIDxiPlBhbDwvYj4h",
|
|
|
|
|
"data:text/html;base64,PGEgaHJlZj0iaW5kZXguaHRtbCI+SG9tZTwvYT4K",
|
|
|
|
@ -128,7 +130,7 @@ fn passing_from_data_url_to_data_url() -> Result<(), ParseError> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn passing_from_file_url_to_relative_path() -> Result<(), ParseError> {
|
|
|
|
|
fn from_file_url_to_relative_path() -> Result<(), ParseError> {
|
|
|
|
|
let resolved_url = utils::resolve_url(
|
|
|
|
|
"file:///home/user/Websites/my-website/index.html",
|
|
|
|
|
"assets/images/logo.png",
|
|
|
|
@ -144,7 +146,7 @@ fn passing_from_file_url_to_relative_path() -> Result<(), ParseError> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn passing_from_file_url_to_relative_path_with_backslashes() -> Result<(), ParseError> {
|
|
|
|
|
fn from_file_url_to_relative_path_with_backslashes() -> Result<(), ParseError> {
|
|
|
|
|
let resolved_url = utils::resolve_url(
|
|
|
|
|
"file:\\\\\\home\\user\\Websites\\my-website\\index.html",
|
|
|
|
|
"assets\\images\\logo.png",
|
|
|
|
@ -160,7 +162,7 @@ fn passing_from_file_url_to_relative_path_with_backslashes() -> Result<(), Parse
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn passing_from_data_url_to_file_url() -> Result<(), ParseError> {
|
|
|
|
|
fn from_data_url_to_file_url() -> Result<(), ParseError> {
|
|
|
|
|
let resolved_url = utils::resolve_url(
|
|
|
|
|
"data:text/html;base64,V2VsY29tZSBUbyBUaGUgUGFydHksIDxiPlBhbDwvYj4h",
|
|
|
|
|
"file:///etc/passwd",
|
|
|
|
@ -173,7 +175,7 @@ fn passing_from_data_url_to_file_url() -> Result<(), ParseError> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn passing_preserve_fragment() -> Result<(), ParseError> {
|
|
|
|
|
fn preserve_fragment() -> Result<(), ParseError> {
|
|
|
|
|
let resolved_url = utils::resolve_url(
|
|
|
|
|
"http://doesnt-matter.local/",
|
|
|
|
|
"css/fonts/fontmarvelous.svg#fontmarvelous",
|
|
|
|
@ -189,7 +191,7 @@ fn passing_preserve_fragment() -> Result<(), ParseError> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn passing_resolve_from_file_url_to_file_url() -> Result<(), ParseError> {
|
|
|
|
|
fn resolve_from_file_url_to_file_url() -> Result<(), ParseError> {
|
|
|
|
|
let resolved_url = if cfg!(windows) {
|
|
|
|
|
utils::resolve_url("file:///c:/index.html", "file:///c:/image.png").unwrap_or(str!())
|
|
|
|
|
} else {
|
|
|
|
@ -207,6 +209,7 @@ fn passing_resolve_from_file_url_to_file_url() -> Result<(), ParseError> {
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ███████╗ █████╗ ██╗██╗ ██╗███╗ ██╗ ██████╗
|
|
|
|
|
// ██╔════╝██╔══██╗██║██║ ██║████╗ ██║██╔════╝
|
|
|
|
@ -215,8 +218,13 @@ fn passing_resolve_from_file_url_to_file_url() -> Result<(), ParseError> {
|
|
|
|
|
// ██║ ██║ ██║██║███████╗██║██║ ╚████║╚██████╔╝
|
|
|
|
|
// ╚═╝ ╚═╝ ╚═╝╚═╝╚══════╝╚═╝╚═╝ ╚═══╝ ╚═════╝
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod failing {
|
|
|
|
|
use crate::utils;
|
|
|
|
|
use url::ParseError;
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn failing_from_data_url_to_url_with_no_protocol() -> Result<(), ParseError> {
|
|
|
|
|
fn from_data_url_to_url_with_no_protocol() -> Result<(), ParseError> {
|
|
|
|
|
let resolved_url = utils::resolve_url(
|
|
|
|
|
"data:text/html;base64,V2VsY29tZSBUbyBUaGUgUGFydHksIDxiPlBhbDwvYj4h",
|
|
|
|
|
"//www.w3schools.com/html/html_iframe.asp",
|
|
|
|
@ -227,3 +235,4 @@ fn failing_from_data_url_to_url_with_no_protocol() -> Result<(), ParseError> {
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|