{"record":{"id":"bb1b72f6df1800bc","repo":"tinyhumansai/openhuman","slug":"pattern-rule-regex-is-well-formed","errorCode":null,"errorMessage":"pattern rule regex is well-formed","messagePattern":"pattern rule regex is well-formed","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/openhuman/security/pii/rules.rs","lineNumber":46,"sourceCode":"}\n\n/// Build a keyword rule: a case-insensitive, word-boundaried alternation over\n/// `terms`, all attributed to `category`.\nfn keyword_rule(category: PiiCategory, terms: &[&str]) -> Rule {\n    let alternation = terms.join(\"|\");\n    let pattern = format!(r\"(?i)\\b(?:{alternation})\\b\");\n    Rule {\n        category,\n        regex: Regex::new(&pattern).expect(\"keyword rule regex is well-formed\"),\n        validator: None,\n    }\n}\n\n/// Build a pattern rule from a raw regex string.\nfn pattern_rule(category: PiiCategory, pattern: &str, validator: Option<fn(&str) -> bool>) -> Rule {\n    Rule {\n        category,\n        regex: Regex::new(pattern).expect(\"pattern rule regex is well-formed\"),\n        validator,\n    }\n}\n\n/// Luhn checksum validation for candidate payment-card numbers. Strips\n/// separators first; requires 13–19 digits.\npub(crate) fn is_luhn_valid(raw: &str) -> bool {\n    let digits: Vec<u8> = raw\n        .bytes()\n        .filter(|b| b.is_ascii_digit())\n        .map(|b| b - b'0')\n        .collect();\n    if !(13..=19).contains(&digits.len()) {\n        return false;\n    }\n    let mut sum = 0u32;\n    // Double every second digit from the right.\n    for (i, &d) in digits.iter().rev().enumerate() {","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/tinyhumansai/openhuman/blob/749120085864ce16e0f273c7b86fac7740b39c5b/src/openhuman/security/pii/rules.rs#L28-L64","documentation":"Static-invariant panic in pattern_rule(): the PII rule table embeds raw regex pattern strings, and Regex::new expects them to be well-formed. A failure means a developer typo in the pattern literal (unbalanced group, bad escape) at table-build time — not a user-input problem, since no runtime string reaches this constructor.","triggerScenarios":"Thrown at src/openhuman/security/pii/rules.rs:46 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix the malformed pattern literal in the rule table","Cover every pattern with a compile-time test that runs Regex::new over the table","Lint pattern literals (clippy's regex checks) to catch drift before release"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"749120085864ce16e0f273c7b86fac7740b39c5b","analyzedAt":"2026-08-17T21:21:45.363Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}