Add check to ensure parsed URL equals link

This commit is contained in:
RumovZ 2021-07-23 11:44:19 +02:00
parent 6ef52726da
commit 503bdb8c22

View file

@ -70,18 +70,28 @@ mod test {
} }
async fn check_page(page: HelpPage, ctx: &BasicContext) -> Outcome { async fn check_page(page: HelpPage, ctx: &BasicContext) -> Outcome {
match Url::parse(&page.to_link()) { let link = page.to_link();
Ok(url) => match check_web(&url, ctx).await { match Url::parse(&link) {
Ok(()) => Outcome::Valid, Ok(url) => {
Err(Reason::Dom) => Outcome::Invalid(format!( if url.as_str() == link {
"'#{}' not found on '{}{}'", match check_web(&url, ctx).await {
url.fragment().unwrap(), Ok(()) => Outcome::Valid,
url.domain().unwrap(), Err(Reason::Dom) => Outcome::Invalid(format!(
url.path(), "'#{}' not found on '{}{}'",
)), url.fragment().unwrap(),
Err(Reason::Web(err)) => Outcome::Invalid(err.to_string()), url.domain().unwrap(),
_ => unreachable!(), 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()), Err(err) => Outcome::Invalid(err.to_string()),
} }
} }