{"record":{"id":"5e1b8dd9e89074a6","repo":"dbt-labs/dbt-core","slug":"error-5e1b8d","errorCode":null,"errorMessage":"[/\\\\]","messagePattern":"\\[/\\\\\\\\\\]","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"info","filePath":"crates/dbt-parser/src/resolve/resolve_tests/persist_generic_data_tests.rs","lineNumber":1140,"sourceCode":"            })?\n        }\n        _ => dbt_yaml::Value::Mapping(dbt_yaml::Mapping::new(), Span::default()),\n    };\n\n    Ok(merge_yaml_values(passed_in_cfg, embedded_cfg))\n}\n\nstatic CLEAN_REGEX: LazyLock<Regex> =\n    LazyLock::new(|| Regex::new(r\"[^0-9a-zA-Z_]+\").expect(\"valid regex\"));\n\n/// Narrow sanitizer for the test-name segments that become a filename\n/// (`source_name` / `resource_name`). The synthesized name is used directly\n/// as `target/generic_tests/<name>.sql`, so only path separators must be\n/// rewritten — anything else is left alone to avoid changing test names /\n/// `unique_id`s for inputs that already worked (e.g. `prod.events`,\n/// `my-source`).\nstatic PATH_UNSAFE_REGEX: LazyLock<Regex> =\n    LazyLock::new(|| Regex::new(r\"[/\\\\]\").expect(\"valid regex\"));\n\n/// Generates a unique hash for a generic test based on uncleaned kwargs.\n/// This matches mantle's behavior where the unique_id includes a hash of the\n/// test metadata (namespace, name, kwargs) WITHOUT cleaning, ensuring that\n/// tests with different expressions (e.g., '> 0' vs '= 0') get different\n/// unique_ids even if their cleaned names would be identical.\n///\n/// https://github.com/dbt-labs/dbt-core/blob/2ef17b836e39d1b4c7a55f14b448a2254378302e/core/dbt/parser/schema_generic_tests.py#L104-L117\nfn generate_test_unique_id_hash(\n    fqn_name: &str,\n    test_macro_name: &str,\n    namespace: Option<&String>,\n    kwargs: &BTreeMap<String, Value>,\n) -> String {\n    const HASH_LENGTH: usize = 10;\n\n    // Mantle builds test_metadata as:\n    //   metadata = {\"namespace\": builder.namespace, \"name\": builder.name, \"kwargs\": builder.args}","sourceCodeStart":1122,"sourceCodeEnd":1158,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-parser/src/resolve/resolve_tests/persist_generic_data_tests.rs#L1122-L1158","documentation":"A panic from `Regex::new(r\"[/\\\\]\").expect(\"valid regex\")` — the compile-time-constant `PATH_UNSAFE_REGEX` used to rewrite path separators in test-name segments that become filenames under `target/generic_tests/`. Like the sibling `CLEAN_REGEX`, the pattern is a hardcoded, syntactically valid literal, so the expect should never fail in normal operation; it only fires if the regex engine fails to compile a known-good pattern.","triggerScenarios":"Practically never from user data — the pattern is static and only matches `/` or `\\`. It can trigger on first use of `PATH_UNSAFE_REGEX` if the regex runtime fails to compile the literal, e.g. an edited/invalid constant, a broken regex crate build, or a runtime fault during lazy initialization.","commonSituations":"A developer edits the constant and introduces invalid regex syntax (e.g. an unescaped lone backslash); a patched or misbuilt regex dependency; extreme environments where lazy static initialization fails.","solutions":["If the constant was modified, restore the valid pattern `[/\\\\]` (in Rust source: `r\"[/\\\\]\"` matches `/` and `\\`)","Rebuild and run tests covering generic-test filename sanitization to catch static regex errors early","If it reproduces with the stock pattern, check the regex crate version for regressions and pin/upgrade accordingly"],"exampleFix":"// before (edited, invalid)\nstatic PATH_UNSAFE_REGEX: LazyLock<Regex> =\n    LazyLock::new(|| Regex::new(r\"[/\").expect(\"valid regex\"));\n\n// after\nstatic PATH_UNSAFE_REGEX: LazyLock<Regex> =\n    LazyLock::new(|| Regex::new(r\"[/\\\\]\").expect(\"valid regex\"));","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// wrap parser invocation; this panic is not user-recoverable, but catch at a boundary\nlet result = std::panic::catch_unwind(|| run_parse(...));\nif result.is_err() {\n    eprintln!(\"parser panicked compiling internal regex; check regex crate build/version\");\n}","preventionTips":["Do not edit static regex constants without validating the pattern (mind backslash escaping in r\"[/\\\\]\")","Add a unit test that touches PATH_UNSAFE_REGEX so bad edits fail at test time, not at runtime","Pin a known-good regex crate version","Keep panic boundaries around parse entry points in embedded/library usage"],"tags":["rust","regex","static-initialization","path-sanitization"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"0267ce9170576975b76b64ce856b2e5848e96617","analyzedAt":"2026-09-07T21:53:39.732Z","contentChangedAt":"2026-09-07T21:53:39.732Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}