{"record":{"id":"a3e89ff8eed30968","repo":"Hmbown/CodeWhale","slug":"markdown-link-regex","errorCode":null,"errorMessage":"markdown link regex","messagePattern":"markdown link regex","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tui/src/tools/web_run.rs","lineNumber":1400,"sourceCode":"    let decoded = decode_html_entities(&without_tags);\n\n    let mut lines = Vec::new();\n    for line in decoded.lines() {\n        let trimmed = normalize_whitespace(line);\n        if trimmed.is_empty() {\n            continue;\n        }\n        for wrapped in wrap_line(&trimmed, ResponseLength::Medium.wrap_width()) {\n            lines.push(wrapped);\n        }\n    }\n\n    (lines, links, title)\n}\n\nfn parse_markdown(markdown: &str, base_url: &str) -> (Vec<String>, Vec<WebLink>) {\n    let re = MARKDOWN_LINK_RE.get_or_init(|| {\n        Regex::new(r#\"\\[([^\\]]+)\\]\\(([^\\s)]+)(?:\\s+\"[^\"]*\")?\\)\"#).expect(\"markdown link regex\")\n    });\n    let mut links = Vec::new();\n    let mut replaced = String::with_capacity(markdown.len());\n    let mut last = 0;\n    for capture in re.captures_iter(markdown) {\n        let Some(full) = capture.get(0) else { continue };\n        let Some(text) = capture.get(1) else { continue };\n        let Some(target) = capture.get(2) else {\n            continue;\n        };\n        replaced.push_str(&markdown[last..full.start()]);\n        let id = links.len() + 1;\n        let text = normalize_whitespace(text.as_str());\n        let url = resolve_url(base_url, target.as_str());\n        links.push(WebLink {\n            id,\n            url,\n            text: text.clone(),","sourceCodeStart":1382,"sourceCodeEnd":1418,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/tui/src/tools/web_run.rs#L1382-L1418","documentation":"Compilation assertion for MARKDOWN_LINK_RE ([text](url \"title\")) used by parse_markdown to extract links. The expect fires only if the hardcoded literal fails to compile when first initialized — a developer error in the pattern text, not a failure triggered by the markdown content being parsed.","triggerScenarios":"Thrown at crates/tui/src/tools/web_run.rs:1400 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Exercise parse_markdown in a unit test so the get_or_init runs under CI","Keep the pattern literal; escape special characters correctly when modifying it","Consider once_cell Lazy combined with a const-pattern check if more regexes are added"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}