From 59ddc1e27d2575f141ca7ea4f0d437400598217e Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 26 Feb 2023 14:00:36 +0100 Subject: [PATCH] Fix url input handling without scheme --- lychee-lib/src/types/input.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lychee-lib/src/types/input.rs b/lychee-lib/src/types/input.rs index c6a4e99..7712ae1 100644 --- a/lychee-lib/src/types/input.rs +++ b/lychee-lib/src/types/input.rs @@ -147,8 +147,12 @@ impl Input { let path = PathBuf::from(value); if path.exists() { InputSource::FsPath(path) - } else if path.is_relative() { - // If the file does not exist and it is a relative path, exit immediately + } else if value.starts_with('~') || value.starts_with('.') { + // The path is not valid, but it might be a valid URL + // Check if the path starts with a tilde or a dot + // and exit early if it does + // This check might not be sufficient to cover all cases + // but it catches the most common ones return Err(ErrorKind::FileNotFound(path)); } else { // Invalid path; check if a valid URL can be constructed from the input @@ -444,4 +448,13 @@ mod tests { &child.to_path_buf() )); } + + #[test] + fn test_url_without_scheme() { + let input = Input::new("example.com", None, false, None); + assert_eq!( + input.unwrap().source.to_string(), + String::from("http://example.com/") + ); + } }