{"record":{"id":"3f1c2f2bf08515e9","repo":"quickwit-oss/quickwit","slug":"regular-expression-should-compile","errorCode":null,"errorMessage":"regular expression should compile","messagePattern":"regular expression should compile","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"quickwit/quickwit-common/src/uri.rs","lineNumber":146,"sourceCode":"        Path::new(&self.uri).extension()?.to_str()\n    }\n\n    /// Returns the URI as a string slice.\n    pub fn as_str(&self) -> &str {\n        &self.uri\n    }\n\n    /// Returns the protocol of the URI.\n    pub fn protocol(&self) -> Protocol {\n        self.protocol\n    }\n\n    /// Strips sensitive information such as credentials from URI.\n    fn as_redacted_str(&self) -> Cow<'_, str> {\n        if self.protocol().is_database() {\n            static DATABASE_URI_PATTERN: LazyLock<Regex> = LazyLock::new(|| {\n                Regex::new(\"(?P<before>^.*://.*)(?P<password>:.*@)(?P<after>.*)\")\n                    .expect(\"regular expression should compile\")\n            });\n            DATABASE_URI_PATTERN.replace(&self.uri, \"$before:***redacted***@$after\")\n        } else {\n            Cow::Borrowed(&self.uri)\n        }\n    }\n\n    pub fn redact(&mut self) {\n        self.uri = self.as_redacted_str().into_owned();\n    }\n\n    /// Returns the file path of the URI.\n    /// Applies only to `file://` and `ram://` URIs.\n    pub fn filepath(&self) -> Option<&Path> {\n        if self.protocol().is_file_storage() {\n            Some(self.path())\n        } else {\n            None","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/quickwit-oss/quickwit/blob/a39730c5cdcd1a4fe798403737ae293999ea21f8/quickwit/quickwit-common/src/uri.rs#L128-L164","documentation":"as_redacted_str builds a static Regex to strip credentials (user:password@) from database URIs before display/logging. The expect fires only if the hard-coded regex '(?P<before>^.*://.*)(?P<password>:.*@)(?P<after>.*)' fails to compile — a compile-time constant in the source, so it can only fail if the pattern string itself is broken (e.g. by an edit introducing invalid regex syntax).","triggerScenarios":"Calling Uri::as_redacted_str() (directly or via redact()/Display/fmt) on a database-protocol URI while the embedded DATABASE_URI_PATTERN is invalid. With the shipped pattern this is unreachable; it becomes reachable only when the regex literal in quickwit/quickwit-common/src/uri.rs is modified incorrectly.","commonSituations":"A developer edits the redaction regex (e.g. adds a look-around unsupported by the regex crate, or a malformed named group) and then any log line or Debug/Display of a postgres/mysql URI triggers the panic at first LazyLock initialization.","solutions":["Fix the regex literal in uri.rs: validate syntax (the regex crate does not support lookaround/backreferences) and named-group names.","Test the pattern in isolation with Regex::new in a unit test so it fails at test time rather than at runtime.","If you need features the regex crate lacks, switch engines (e.g. fancy-regex) or rewrite the pattern without lookarounds."],"exampleFix":"// before\nRegex::new(\"(?P<before>^.*://.*)(?P<password>:.*@)(?P<after>.*)\")\n    .expect(\"regular expression should compile\")\n// after (validated at test time; keep runtime expect)\nRegex::new(\"(?P<before>^.*?://.*?)(?P<password>:[^@]*@)(?P<after>.*)\")\n    .expect(\"regular expression should compile\")","handlingStrategy":"validation","validationCode":"Regex::new(\"(?P<before>^.*://.*)(?P<password>:.*@)(?P<after>.*)\").expect(\"regex compiles\"); // run in a unit test / build step","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add a unit test that constructs every LazyLock<Regex> so invalid patterns fail in CI.","Remember the regex crate forbids lookaround/backreferences; keep patterns simple."],"tags":["rust","regex","static-pattern","redaction"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"a39730c5cdcd1a4fe798403737ae293999ea21f8","analyzedAt":"2026-09-08T13:19:37.784Z","contentChangedAt":"2026-09-08T13:19:37.784Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}