{"record":{"id":"16aec3024f035b80","repo":"jstedfast/MailKit","slug":"invalid-character-in-annotation-entry-path-c","errorCode":null,"errorMessage":"Invalid character in annotation entry path: '{c}'.","messagePattern":"Invalid character in annotation entry path: '(.+?)'\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"MailKit/AnnotationEntry.cs","lineNumber":135,"sourceCode":"\t\t\tif (path.Length == 0)\n\t\t\t\tthrow new ArgumentException (\"Annotation entry paths cannot be empty.\", nameof (path));\n\n\t\t\tif (path[0] != '/' && path[0] != '*' && path[0] != '%')\n\t\t\t\tthrow new ArgumentException (\"Annotation entry paths must begin with '/'.\", nameof (path));\n\n\t\t\tif (path.Length > 1 && path[1] >= '0' && path[1] <= '9')\n\t\t\t\tthrow new ArgumentException (\"Annotation entry paths must not include a part-specifier.\", nameof (path));\n\n\t\t\tif (path == \"*\" || path == \"%\")\n\t\t\t\treturn;\n\n\t\t\tchar pc = path[0];\n\n\t\t\tfor (int i = 1; i < path.Length; i++) {\n\t\t\t\tchar c = path[i];\n\n\t\t\t\tif (c > 127)\n\t\t\t\t\tthrow new ArgumentException ($\"Invalid character in annotation entry path: '{c}'.\", nameof (path));\n\n\t\t\t\tif (c >= '0' && c <= '9' && pc == '/')\n\t\t\t\t\tthrow new ArgumentException (\"Invalid annotation entry path.\", nameof (path));\n\n\t\t\t\tif ((pc == '/' || pc == '.') && (c == '/' || c == '.'))\n\t\t\t\t\tthrow new ArgumentException (\"Invalid annotation entry path.\", nameof (path));\n\n\t\t\t\tpc = c;\n\t\t\t}\n\n\t\t\tint endIndex = path.Length - 1;\n\n\t\t\tif (path[endIndex] == '/')\n\t\t\t\tthrow new ArgumentException (\"Annotation entry paths must not end with '/'.\", nameof (path));\n\n\t\t\tif (path[endIndex] == '.')\n\t\t\t\tthrow new ArgumentException (\"Annotation entry paths must not end with '.'.\", nameof (path));\n\t\t}","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/AnnotationEntry.cs#L117-L153","documentation":"AnnotationEntry.ValidatePath throws ArgumentException when any character after the first is > 127 (non-ASCII). IMAP annotation entry paths are restricted to ASCII (astring characters), so characters like accents, emoji, or CJK text are rejected with a message naming the offending character.","triggerScenarios":"Calling `new AnnotationEntry(\"/commentaire-café\", scope)` or paths built from localized/user-provided text containing any character with code point above 127.","commonSituations":"Localizing annotation keys; user-supplied annotation names; copy-pasting paths containing typographic quotes, non-breaking spaces, or accented letters.","solutions":["Replace all non-ASCII characters in the path with ASCII equivalents before constructing AnnotationEntry.","Validate the path in UI/input code to restrict it to ASCII characters (code point <= 127).","If a localized label is needed, store it in the annotation value, not the entry path."],"exampleFix":"// before\nvar entry = new AnnotationEntry(\"/commenté\", AnnotationScope.Shared);\n// after\nvar entry = new AnnotationEntry(\"/commente\", AnnotationScope.Shared);","handlingStrategy":"validation","validationCode":"static bool IsAscii(string s) => s != null && s.All(c => c <= 127);\nif (!IsAscii(path))\n    throw new FormatException(\"Annotation entry path must be ASCII only\");","typeGuard":"bool IsAsciiEntryPath(string p) => p != null && p.Length > 0 && p.All(c => c <= 127);","tryCatchPattern":"try\n{\n    var entry = new AnnotationEntry(path, AnnotationScope.Shared);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Invalid character\"))\n{\n    // transliterate or reject non-ASCII input\n}","preventionTips":["Restrict annotation entry names to ASCII in UIs and config schemas.","Validate every character is <= 127 before construction.","Store localized/human text in annotation values, not entry paths."],"tags":["mailkit","imap","annotations","ascii","path-format"],"backgroundTag":"invalid-argument-value","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}