Hmbown/CodeWhale · error

tag regex

Error message

tag regex

What it means

Compilation assertion for TAG_RE (r"<[^>]+>"), which strips HTML tags during page-to-text conversion. The expect fires only when this hardcoded literal fails to compile — a developer mistake at first use of get_tag_re, since OnceLock defers Regex::new until the first parse call.

Source

Thrown at crates/tui/src/tools/web_run.rs:1352

// === HTML Parsing ===

static ANCHOR_RE: OnceLock<Regex> = OnceLock::new();
static TAG_RE: OnceLock<Regex> = OnceLock::new();
static BLOCK_RE: OnceLock<Regex> = OnceLock::new();
static SCRIPT_RE: OnceLock<Regex> = OnceLock::new();
static STYLE_RE: OnceLock<Regex> = OnceLock::new();
static TITLE_RE: OnceLock<Regex> = OnceLock::new();
static MARKDOWN_LINK_RE: OnceLock<Regex> = OnceLock::new();

fn get_anchor_re() -> &'static Regex {
    ANCHOR_RE.get_or_init(|| {
        Regex::new(r#"(?is)<a\s+[^>]*href\s*=\s*['\"]([^'\"]+)['\"][^>]*>(.*?)</a>"#)
            .expect("anchor regex")
    })
}

fn get_tag_re() -> &'static Regex {
    TAG_RE.get_or_init(|| Regex::new(r"<[^>]+>").expect("tag regex"))
}

fn get_block_re() -> &'static Regex {
    BLOCK_RE.get_or_init(|| {
        Regex::new(r"(?is)</?(p|div|li|ul|ol|br|h[1-6]|tr|td|th|table|section|article)[^>]*>")
            .expect("block regex")
    })
}

fn get_script_re() -> &'static Regex {
    SCRIPT_RE.get_or_init(|| Regex::new(r"(?is)<script[^>]*>.*?</script>").unwrap())
}

fn get_style_re() -> &'static Regex {
    STYLE_RE.get_or_init(|| Regex::new(r"(?is)<style[^>]*>.*?</style>").unwrap())
}

fn get_title_re() -> &'static Regex {

View on GitHub (pinned to 0c42157ee5)

Solutions

  1. Cover get_tag_re in a unit test so an invalid literal fails in CI
  2. Keep the pattern a static literal; no runtime construction path exists
  3. Use regex crate syntax checks (regex_tests or a compile test) when editing the pattern
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/tui/src/tools/web_run.rs:1352 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/1249eae99338ecd2. Report an issue: GitHub.