use url::Url;
pub(crate) fn html_escape(s: &str) -> String {
s.replace('&', "&")
.replace('<', "<")
.replace('>', ">")
.replace('"', """)
}
pub(crate) fn resolve_url(
src: &str,
baseurl: &str,
page_url: &str,
) -> Result<Url, url::ParseError> {
Url::parse(src)
.or_else(|_| {
if !baseurl.is_empty() {
Url::parse(baseurl).and_then(|b| b.join(src))
} else {
Err(url::ParseError::RelativeUrlWithoutBase)
}
})
.or_else(|_| Url::parse(page_url).and_then(|base| base.join(src)))
}
pub(crate) fn is_same_page(a: &Url, b: &Url) -> bool {
a.scheme() == b.scheme()
&& a.host() == b.host()
&& a.port() == b.port()
&& a.path() == b.path()
&& a.query() == b.query()
}