add ending slash, reorganize conditions

This commit is contained in:
yggverse 2025-03-15 13:55:27 +02:00
parent 0364760a35
commit 2870aeb3fb
2 changed files with 10 additions and 14 deletions

View file

@ -32,22 +32,18 @@ impl Link {
// Relative scheme patch // Relative scheme patch
// https://datatracker.ietf.org/doc/html/rfc3986#section-4.2 // https://datatracker.ietf.org/doc/html/rfc3986#section-4.2
if let Some(p) = unresolved_address.strip_prefix("//") { if let Some(p) = unresolved_address.strip_prefix("//") {
let b = base?;
let postfix = p.trim_start_matches(":"); let postfix = p.trim_start_matches(":");
match base {
Some(b) => {
unresolved_address = format!( unresolved_address = format!(
"{}://{}", "{}://{}",
b.scheme(), b.scheme(),
if postfix.is_empty() { if postfix.is_empty() {
b.host()? format!("{}/", b.host()?)
} else { } else {
postfix.into() postfix.into()
} }
) )
} }
None => return None,
}
}
// Convert address to the valid URI // Convert address to the valid URI
let uri = match base { let uri = match base {
// Base conversion requested // Base conversion requested

View file

@ -227,7 +227,7 @@ fn gemtext() {
assert_eq!(item.alt, None); assert_eq!(item.alt, None);
assert_eq!(item.timestamp, None); assert_eq!(item.timestamp, None);
assert_eq!(item.uri.to_str(), "gemini://geminiprotocol.net"); assert_eq!(item.uri.to_str(), "gemini://geminiprotocol.net/");
} // #8 } // #8
// Validate lists // Validate lists