Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions fixtures/TEST_LOCAL_DIRECTORIES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
The following links should all be valid and be detected as such by lychee.

[link to root dir](file:///)
[link to /dev](file:///dev/)
[link to current dir](.)
[relative link to docs](../docs/)
19 changes: 16 additions & 3 deletions lychee-bin/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,15 @@ mod cli {
let test_path = fixtures_path().join($test_file);
let outfile = format!("{}.json", uuid::Uuid::new_v4());

cmd$(.arg($arg))*.arg("--output").arg(&outfile).arg("--format").arg("json").arg(test_path).assert().success();
let result = cmd$(.arg($arg))*.arg("--output").arg(&outfile).arg("--format").arg("json").arg(test_path).assert();

let output = std::fs::read_to_string(&outfile)?;
std::fs::remove_file(outfile)?;

let actual: Value = serde_json::from_str(&output)?;
let expected: Value = serde_json::to_value(&$expected)?;

result.success();
assert_json_include!(actual: actual, expected: expected);
Ok(())
}};
Expand Down Expand Up @@ -280,6 +281,18 @@ mod cli {
)
}

#[test]
fn test_local_directories() -> Result<()> {
test_json_output!(
"TEST_LOCAL_DIRECTORIES.md",
MockResponseStats {
total: 4,
successful: 4,
..MockResponseStats::default()
}
)
}

#[test]
fn test_email() -> Result<()> {
test_json_output!(
Expand Down Expand Up @@ -1915,9 +1928,9 @@ mod cli {
"https://raw.githubusercontent.com/lycheeverse/lychee/master/fixtures/fragments/zero.bin#fragment",
))
.stdout(contains("42 Total"))
.stdout(contains("30 OK"))
.stdout(contains("31 OK"))
// Failures because of missing fragments or failed binary body scan
.stdout(contains("12 Errors"));
.stdout(contains("11 Errors"));
}

#[test]
Expand Down
6 changes: 6 additions & 0 deletions lychee-lib/src/checker/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,17 @@ impl FileChecker {
/// Returns a `Status` indicating the result of the check.
async fn check_path(&self, path: &Path, uri: &Uri) -> Status {
let file_path = self.resolve_file_path(path);
let has_fragment = uri.url.fragment().is_some_and(|x| !x.is_empty());

// If file_path exists, check this file
if file_path.is_some() {
return self.check_file(&file_path.unwrap(), uri).await;
}
// If path is a directory, and we cannot find an index file inside it,
// and we don't have a fragment, just return success.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original comment:

// If path is a directory, and we cannot find an index file inside it,
// and we don't have a fragment, just return success. This is for
// backward compatibility.

I do not agree with the original statement This is for backward compatibility. lychee should not mark directories that exist with ErrorKind::InvalidFilePath.

else if path.is_dir() && !has_fragment {
return Status::Ok(StatusCode::OK);
}

ErrorKind::InvalidFilePath(uri.clone()).into()
}
Expand Down