Hmbown/CodeWhale · error
HTML entity regex
Error message
HTML entity regex
What it means
decode_html_entities() compiles its static HTML character-reference regex inside a OnceLock and unwraps the Regex::new result. The pattern is a fixed literal known to be valid, so failure would indicate a corrupted regex string in the source — never a runtime input problem.
Source
Thrown at crates/tui/src/tools/web/scrape.rs:234
}
href.to_string()
}
fn normalize_text(text: &str) -> String {
let stripped = strip_html_tags(text);
let decoded = decode_html_entities(&stripped);
decoded.split_whitespace().collect::<Vec<_>>().join(" ")
}
fn strip_html_tags(text: &str) -> String {
get_tag_re().replace_all(text, "").to_string()
}
/// Decode common HTML named and numeric character references.
pub fn decode_html_entities(text: &str) -> String {
static ENTITY_RE: OnceLock<Regex> = OnceLock::new();
let re = ENTITY_RE.get_or_init(|| {
Regex::new(r"&(?:#(\d+)|#x([0-9A-Fa-f]+)|([a-zA-Z]+));").expect("HTML entity regex")
});
re.replace_all(text, |caps: ®ex::Captures| {
if let Some(dec) = caps.get(1) {
return dec
.as_str()
.parse::<u32>()
.ok()
.and_then(std::char::from_u32)
.unwrap_or('\u{FFFD}')
.to_string();
}
if let Some(hex) = caps.get(2) {
return u32::from_str_radix(hex.as_str(), 16)
.ok()
.and_then(std::char::from_u32)
.unwrap_or('\u{FFFD}')
.to_string();View on GitHub (pinned to 0c42157ee5)
Solutions
- Verify the ENTITY_RE pattern literal was not corrupted by an edit
- Add a test that forces the OnceLock initialization so bad patterns fail in CI
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at crates/tui/src/tools/web/scrape.rs:234 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of Hmbown/CodeWhale@0c42157ee5 (2026-08-20).
Data as JSON: /api/errors/61f94f2111b4c77c.
Report an issue: GitHub.