Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
trask committed Dec 1, 2024
1 parent d58171f commit 0925bc1
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions lychee-lib/src/utils/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,36 @@ fn try_parse_into_uri(
text = path.to_owned() + &text;
}
}
println!("text: {}", text);
let uri = match Uri::try_from(raw_uri.clone()) {
Ok(uri) => uri,
Ok(uri) => {
println!("uri: {:?}", uri);
uri
},
Err(_) => match base {
Some(base_url) => match base_url.join(&text) {
Some(url) => Uri { url },
None => return Err(ErrorKind::InvalidBaseJoin(text.clone())),
Some(url) => {
println!("url: {:?}", url);
Uri { url }
},
None => {
println!("Error: {:?}", ErrorKind::InvalidBaseJoin(text.clone()));
return Err(ErrorKind::InvalidBaseJoin(text.clone()))
},
},
None => match source {
InputSource::FsPath(root) => create_uri_from_file_path(root, &text, base)?,
_ => return Err(ErrorKind::UnsupportedUriType(text)),
InputSource::FsPath(root) => {
println!("=======================================");
create_uri_from_file_path(root, &text, &None)?
},
_ => {
println!("Error: {:?}", ErrorKind::UnsupportedUriType(text.clone()));
return Err(ErrorKind::UnsupportedUriType(text))
},
},
},
};
println!("RETURNING uri: {:?}", uri);
Ok(uri)
}

Expand All @@ -95,6 +112,8 @@ fn create_uri_from_file_path(
link_text: &str,
base: &Option<Base>,
) -> Result<Uri> {
println!("file_path: {:?}", file_path);
println!("link_text: {:?}", link_text);
let target_path = if is_anchor(link_text) {
// For anchors, we need to append the anchor to the file name.
let file_name = file_path
Expand All @@ -106,6 +125,7 @@ fn create_uri_from_file_path(
} else {
link_text.to_string()
};
println!("link_text: {:?}", link_text);
let Ok(constructed_url) = resolve_and_create_url(file_path, &target_path, base) else {
return Err(ErrorKind::InvalidPathToUri(target_path));
};
Expand Down Expand Up @@ -173,6 +193,9 @@ fn resolve_and_create_url(
dest_path: &str,
base_uri: &Option<Base>,
) -> Result<Url> {
println!("resolve_and_create_url");
println!("src_path: {:?}", src_path);
println!("dest_path: {:?}", dest_path);
let (dest_path, fragment) = url::remove_get_params_and_separate_fragment(dest_path);

// Decode the destination path to avoid double-encoding
Expand All @@ -181,13 +204,16 @@ fn resolve_and_create_url(

let Ok(Some(resolved_path)) = path::resolve(src_path, &PathBuf::from(&*decoded_dest), base_uri)
else {
println!("Error: {:?}", ErrorKind::InvalidPathToUri(decoded_dest.to_string()));
return Err(ErrorKind::InvalidPathToUri(decoded_dest.to_string()));
};

let Ok(mut url) = Url::from_file_path(&resolved_path) else {
println!("Error: {:?}", ErrorKind::InvalidUrlFromPath(resolved_path.clone()));
return Err(ErrorKind::InvalidUrlFromPath(resolved_path.clone()));
};

println!("OK!");
url.set_fragment(fragment);
Ok(url)
}
Expand Down

0 comments on commit 0925bc1

Please sign in to comment.