{"record":{"id":"797befed6b31414f","repo":"GitoxideLabs/gitoxide","slug":"no-illformed-utf8","errorCode":null,"errorMessage":"no illformed utf8","messagePattern":"no illformed utf8","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"gix-attributes/src/name.rs","lineNumber":40,"sourceCode":"        self.0\n    }\n}\n\nimpl<'a> TryFrom<&'a BStr> for NameRef<'a> {\n    type Error = Error;\n\n    fn try_from(attr: &'a BStr) -> Result<Self, Self::Error> {\n        fn attr_valid(attr: &BStr) -> bool {\n            if attr.is_empty() || attr.first() == Some(&b'-') {\n                return false;\n            }\n\n            attr.bytes()\n                .all(|b| matches!(b, b'-' | b'.' | b'_' | b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9'))\n        }\n\n        attr_valid(attr)\n            .then(|| NameRef(attr.to_str().expect(\"no illformed utf8\")))\n            .ok_or_else(|| Error { attribute: attr.into() })\n    }\n}\n\nimpl<'a> Name {\n    /// Provide our ref-type.\n    pub fn as_ref(&'a self) -> NameRef<'a> {\n        NameRef(self.as_str())\n    }\n\n    /// Return the inner `str`.\n    pub fn as_str(&self) -> &str {\n        &self.0\n    }\n}\n\nimpl AsRef<str> for Name {\n    fn as_ref(&self) -> &str {","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-attributes/src/name.rs#L22-L58","documentation":"`NameRef::try_from` validates attribute names against an ASCII allowlist (`-._A-Za-z0-9`). Since the byte check guarantees ASCII, `to_str()` is expected to succeed; the `.expect(\"no illformed utf8\")` panics only if the validation predicate and conversion fall out of sync.","triggerScenarios":"Parsing a `.gitattributes` file whose attribute name contains bytes outside the allowlist — this produces the `Error { attribute }` (no panic); the panic itself only occurs if `attr_valid` accepts non-UTF-8 bytes due to a predicate bug.","commonSituations":"Malformed `.gitattributes` entries with unusual characters (e.g. non-ASCII names) yield the regular `name::Error`; developers editing the validation predicate could introduce the panic path.","solutions":["Fix the attribute name in `.gitattributes` to use only `-`, `.`, `_`, letters and digits.","Keep `attr_valid` and the `to_str()` conversion in sync — the predicate already implies ASCII/UTF-8 safety.","Handle the returned `name::Error` instead of relying on the expect path."],"exampleFix":"// .gitattributes before\n*.rs mein-atträbute text\n\n// after\n*.rs my-attr text","handlingStrategy":"validation","validationCode":"fn attr_name_valid(name: &[u8]) -> bool {\n    !name.is_empty()\n        && name.iter().all(|b| matches!(b, b'-' | b'.' | b'_' | b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9'))\n}","typeGuard":null,"tryCatchPattern":"match NameRef::try_from(attr) {\n    Ok(name) => use(name),\n    Err(e) => report_bad_attribute(&e.attribute),\n}","preventionTips":["Use only [-._A-Za-z0-9] in .gitattributes attribute names","Handle NameRef::try_from errors rather than assuming validity","Keep the validation predicate consistent with any UTF-8 conversion downstream"],"tags":["gitattributes","attributes","validation","utf8"],"backgroundTag":"invalid-identifier-format","analyzedSha":"e73179060badf27222d790981fac3f84c1830a7e","analyzedAt":"2026-09-08T11:26:50.865Z","contentChangedAt":"2026-09-08T11:26:50.865Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}