mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-22 20:31:19 +00:00
Adding back in doctype check.
This commit is contained in:
parent
b60e511493
commit
b93f76b157
1 changed files with 12 additions and 0 deletions
|
@ -184,6 +184,18 @@ pub async fn generate_post_link_metadata(
|
||||||
fn extract_opengraph_data(html_bytes: &[u8], url: &Url) -> LemmyResult<OpenGraphData> {
|
fn extract_opengraph_data(html_bytes: &[u8], url: &Url) -> LemmyResult<OpenGraphData> {
|
||||||
let html = String::from_utf8_lossy(html_bytes);
|
let html = String::from_utf8_lossy(html_bytes);
|
||||||
|
|
||||||
|
// Make sure the first line is doctype html
|
||||||
|
let first_line = html
|
||||||
|
.trim_start()
|
||||||
|
.lines()
|
||||||
|
.next()
|
||||||
|
.ok_or(LemmyErrorType::NoLinesInHtml)?
|
||||||
|
.to_lowercase();
|
||||||
|
|
||||||
|
if !first_line.starts_with("<!doctype html") {
|
||||||
|
Err(LemmyErrorType::SiteMetadataPageIsNotDoctypeHtml)?
|
||||||
|
}
|
||||||
|
|
||||||
let mut page = HTML::from_string(html.to_string(), None)?;
|
let mut page = HTML::from_string(html.to_string(), None)?;
|
||||||
|
|
||||||
// If the web page specifies that it isn't actually UTF-8, re-decode the received bytes with the
|
// If the web page specifies that it isn't actually UTF-8, re-decode the received bytes with the
|
||||||
|
|
Loading…
Reference in a new issue