Fix hanime-cdn relative path prefixing and stale vidara test
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MUYdCh2nCVsQYgJAT7gwSi
This commit is contained in:
@@ -12,8 +12,16 @@ fn normalize_image_url(endpoint: &str) -> String {
|
||||
endpoint.to_string()
|
||||
} else if endpoint.starts_with("hanime-cdn.com/") || endpoint == "hanime-cdn.com" {
|
||||
format!("https://{endpoint}")
|
||||
} else {
|
||||
} else if endpoint
|
||||
.split('/')
|
||||
.next()
|
||||
.is_some_and(|first| first.contains('.'))
|
||||
{
|
||||
// `other-host.tld/path`: the caller already supplied a host.
|
||||
format!("https://{endpoint}")
|
||||
} else {
|
||||
// Site-relative path such as `images/covers/x.png`.
|
||||
format!("https://hanime-cdn.com/{endpoint}")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -116,9 +116,14 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn normalizes_detail_request_with_path_only() {
|
||||
let (url, video_id) = VidaraProxy::normalize_detail_request("video/1000/demo")
|
||||
let (url, video_id) = VidaraProxy::normalize_detail_request("v/eJ9O4QqG1Ln2")
|
||||
.expect("detail request should parse");
|
||||
assert_eq!(url, "https://vidara.so/video/1000/demo");
|
||||
assert_eq!(video_id, "1000");
|
||||
assert_eq!(url, "https://vidara.so/v/eJ9O4QqG1Ln2");
|
||||
assert_eq!(video_id, "eJ9O4QqG1Ln2");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_paths_outside_the_embed_route() {
|
||||
assert!(VidaraProxy::normalize_detail_request("video/1000/demo").is_none());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user