{"record":{"id":"b2126035a4da22e9","repo":"denisidoro/navi","slug":"invalid-regex","errorCode":null,"errorMessage":"Invalid regex","messagePattern":"Invalid regex","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/finder/post.rs","lineNumber":46,"sourceCode":"            )\n        };\n\n        let output = shell::out()\n            .arg(cmd.as_str())\n            .stderr(Stdio::inherit())\n            .output()\n            .context(\"Failed to execute map function\")?;\n\n        String::from_utf8(output.stdout).context(\"Invalid utf8 output for map function\")\n    } else {\n        Ok(text)\n    }\n}\n\nfn get_column(text: String, column: Option<u8>, delimiter: Option<&str>) -> String {\n    if let Some(c) = column {\n        let mut result = String::from(\"\");\n        let re = regex::Regex::new(delimiter.unwrap_or(r\"\\s\\s+\")).expect(\"Invalid regex\");\n        for line in text.split('\\n') {\n            if (line).is_empty() {\n                continue;\n            }\n            let mut parts = re.split(line).skip((c - 1) as usize);\n            if !result.is_empty() {\n                result.push('\\n');\n            }\n            result.push_str(parts.next().unwrap_or(\"\"));\n        }\n        result\n    } else {\n        text\n    }\n}\n\npub fn process(\n    text: String,","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/denisidoro/navi/blob/f7330b9ad5bd95b7d1a3c96d00e0a77deb589147/src/finder/post.rs#L28-L64","documentation":"This panic comes from `.expect(\"Invalid regex\")` when compiling the delimiter as a regex in `get_column` (src/finder/post.rs:46). The user-supplied `--delimiter` option is passed straight to `regex::Regex::new`, so any syntactically invalid regex pattern causes a hard panic instead of a graceful error. The default delimiter `\\s\\s+` is valid, so this only fires when a custom delimiter string is provided.","triggerScenarios":"Calling the finder's `process` (e.g. via the `--delimiter` CLI flag or the config's delimiter field) with a `column` set and a delimiter string that is not a valid regex — e.g. a lone `\\` (backslash), an unclosed group like `(` or `[`, an invalid repetition like `*foo`, or a stray closing `)`.","commonSituations":"Users pass a literal separator such as `\\t` or `|` intending a plain string, but escape it incorrectly (`\\t` becomes a bare backslash + t is fine, but trailing `\\` or half-written patterns panic); copying regex fragments from other tools with syntax the Rust `regex` crate rejects (backreferences like `\\1`, lookarounds `(?=...)`); shell quoting stripping or mangling backslashes before the pattern reaches the code.","solutions":["Fix the delimiter pattern so it is a valid Rust `regex` crate expression (no backreferences, no lookarounds, balanced groups/brackets, no trailing escape)","If you meant a literal separator, escape metacharacters or use a pattern matching it, e.g. delimiter `|` → `\\|`, tab → `\\t` (actual tab character also works)","Patch the code to propagate instead of panicking: match on `Regex::new(...)` and return an `Err` with the regex error so the user sees which pattern failed","Validate the pattern beforehand with `regex::Regex::new(d).is_ok()` when accepting delimiter input in scripts or wrappers"],"exampleFix":"// before\nlet re = regex::Regex::new(delimiter.unwrap_or(r\"\\s\\s+\")).expect(\"Invalid regex\");\n// after\nlet re = regex::Regex::new(delimiter.unwrap_or(r\"\\s\\s+\"))\n    .map_err(|e| anyhow!(\"Invalid regex '{}': {}\", delimiter.unwrap_or(\"\"), e))?;","handlingStrategy":"validation","validationCode":"// Validate the delimiter before passing it to the finder:\nfn delimiter_is_valid(delimiter: &str) -> bool {\n    regex::Regex::new(delimiter).is_ok()\n}\n// e.g.\n// assert!(delimiter_is_valid(\"\\|\"), \"--delimiter must be a valid regex\");","typeGuard":"fn as_valid_regex(delimiter: Option<&str>) -> Option<String> {\n    delimiter.filter(|d| regex::Regex::new(d).is_ok()).map(String::from)\n}","tryCatchPattern":"// Wrap calls that reach get_column when you cannot pre-validate; in Rust\n// panics are caught with catch_unwind, but the better pattern is fixing the input:\nlet result = std::panic::catch_unwind(|| navi_process(text, column, Some(bad_delimiter), None));\nmatch result {\n    Ok(out) => out,\n    Err(_) => eprintln!(\"delimiter '{}' is not a valid regex\", bad_delimiter),\n}","preventionTips":["Treat --delimiter as a REGEX, not a literal string: escape metacharacters (| → \\|, ( → \\()","Avoid regex features unsupported by the Rust regex crate: no backreferences (\\1), no lookarounds ((?=...), (?!...))","Beware shell escaping: quote the pattern so backslashes reach the program intact ('\\t' not \"\\t\" in some shells)","Prefer the default (2+ spaces) or simple patterns like '\\s+' unless column extraction truly needs a custom separator","Test the delimiter with regex::Regex::new or an online Rust regex tester before running large pipelines"],"tags":["regex","panic","invalid-input","user-input","unexpected-unwrap"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"f7330b9ad5bd95b7d1a3c96d00e0a77deb589147","analyzedAt":"2026-09-03T13:58:22.429Z","contentChangedAt":"2026-09-03T13:58:22.429Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}