From a28ae68e49ca406f1f4bafa33606f5310579e063 Mon Sep 17 00:00:00 2001 From: Hugo McNally Date: Wed, 12 Jul 2023 17:36:21 +0100 Subject: [PATCH] Moved fragment check into it's own function. --- lychee-lib/src/client.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lychee-lib/src/client.rs b/lychee-lib/src/client.rs index 980ddaddd0..fa56b2a8c5 100644 --- a/lychee-lib/src/client.rs +++ b/lychee-lib/src/client.rs @@ -13,6 +13,7 @@ clippy::default_trait_access, clippy::used_underscore_binding )] +use std::path::Path; use std::{collections::HashSet, time::Duration}; use tokio::fs::File; use tokio::io::AsyncReadExt; @@ -667,11 +668,20 @@ impl Client { if !path.exists() { return ErrorKind::InvalidFilePath(uri.clone()).into(); } + if self.include_fragments { + Self::check_fragment(&path, uri).await + } else { + Status::Ok(StatusCode::OK) + } + } + + /// Checks a `file` URI's fragment. + pub async fn check_fragment(path: &Path, uri: &Uri) -> Status { let is_md = path .extension() .map_or(false, |ext| ext.eq_ignore_ascii_case("md")); - if let (true, Some(frag), true) = (is_md, uri.url.fragment(), self.include_fragments) { + if let (true, Some(frag)) = (is_md, uri.url.fragment()) { let mut content = String::new(); File::open(path) .await