Skip to content

Commit ac99829

Browse files
authored
fix: do not panic on missing attributes for encoding-related meta elements (#346)
Ignores encoding-related `meta` elements with missing `content` or `charset` attributes. Related to #344
1 parent 4344b1f commit ac99829

File tree

1 file changed

+10
-8
lines changed
  • impit/src/response_parsing

1 file changed

+10
-8
lines changed

impit/src/response_parsing/mod.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,24 @@ fn prescan_bytestream(bytes: &[u8]) -> Option<encoding::EncodingRef> {
4545
.next();
4646

4747
if let Some(meta) = meta {
48-
let charset = meta.value().attr("charset").unwrap();
49-
return encoding::label::encoding_from_whatwg_label(charset);
48+
if let Some(charset) = meta.value().attr("charset") {
49+
return encoding::label::encoding_from_whatwg_label(charset);
50+
}
5051
}
5152

5253
let meta = dom
5354
.select(&scraper::Selector::parse("meta[http-equiv=content-type]").unwrap())
5455
.next();
5556

5657
if let Some(meta) = meta {
57-
let content = meta.value().attr("content").unwrap();
58-
let content_type = ContentType::from(content);
58+
if let Some(content) = meta.value().attr("content") {
59+
let content_type = ContentType::from(content);
5960

60-
return match content_type {
61-
Ok(content_type) => content_type.into(),
62-
Err(_) => None,
63-
};
61+
return match content_type {
62+
Ok(content_type) => content_type.into(),
63+
Err(_) => None,
64+
};
65+
}
6466
}
6567

6668
None

0 commit comments

Comments
 (0)