mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 01:06:35 -04:00
Add check to ensure parsed URL equals link
This commit is contained in:
parent
6ef52726da
commit
503bdb8c22
1 changed files with 22 additions and 12 deletions
|
@ -70,18 +70,28 @@ mod test {
|
|||
}
|
||||
|
||||
async fn check_page(page: HelpPage, ctx: &BasicContext) -> Outcome {
|
||||
match Url::parse(&page.to_link()) {
|
||||
Ok(url) => match check_web(&url, ctx).await {
|
||||
Ok(()) => Outcome::Valid,
|
||||
Err(Reason::Dom) => Outcome::Invalid(format!(
|
||||
"'#{}' not found on '{}{}'",
|
||||
url.fragment().unwrap(),
|
||||
url.domain().unwrap(),
|
||||
url.path(),
|
||||
)),
|
||||
Err(Reason::Web(err)) => Outcome::Invalid(err.to_string()),
|
||||
_ => unreachable!(),
|
||||
},
|
||||
let link = page.to_link();
|
||||
match Url::parse(&link) {
|
||||
Ok(url) => {
|
||||
if url.as_str() == link {
|
||||
match check_web(&url, ctx).await {
|
||||
Ok(()) => Outcome::Valid,
|
||||
Err(Reason::Dom) => Outcome::Invalid(format!(
|
||||
"'#{}' not found on '{}{}'",
|
||||
url.fragment().unwrap(),
|
||||
url.domain().unwrap(),
|
||||
url.path(),
|
||||
)),
|
||||
Err(Reason::Web(err)) => Outcome::Invalid(err.to_string()),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
} else {
|
||||
Outcome::Invalid(format!(
|
||||
"'{}' is not a valid URL part",
|
||||
page.to_link_suffix(),
|
||||
))
|
||||
}
|
||||
}
|
||||
Err(err) => Outcome::Invalid(err.to_string()),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue