{"record":{"id":"d39f36570f1bfa78","repo":"dotnet/wpf","slug":"bracket-characters-cannot-be-alpha-numeric-or-whitespace","errorCode":null,"errorMessage":"Bracket characters cannot be alpha-numeric or whitespace.","messagePattern":"Bracket characters cannot be alpha-numeric or whitespace\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Xaml/Parser/SpecialBracketCharacters.cs","lineNumber":80,"sourceCode":"                    string errorMessage = string.Empty;\n                    if (IsValidBracketCharacter(openingBracket, closingBracket))\n                    {\n                        _startCharactersStringBuilder.Append(openingBracket);\n                        _endCharactersStringBuilder.Append(closingBracket);\n                    }\n                }\n            }\n        }\n\n        private bool IsValidBracketCharacter(char openingBracket, char closingBracket)\n        {\n            if (openingBracket == closingBracket)\n            {\n                throw new InvalidOperationException(\"Opening bracket character cannot be the same as closing bracket character.\");\n            }\n            else if (char.IsLetterOrDigit(openingBracket) || char.IsLetterOrDigit(closingBracket) || char.IsWhiteSpace(openingBracket) || char.IsWhiteSpace(closingBracket))\n            {\n                throw new InvalidOperationException(\"Bracket characters cannot be alpha-numeric or whitespace.\");\n            }\n            else if (_restrictedCharSet.Contains(openingBracket) || _restrictedCharSet.Contains(closingBracket))\n            {\n                throw new InvalidOperationException(\"Bracket characters cannot be one of the following: '=' , ',', '\\'', '\\\"', '{ ', ' }', '\\\\'\");\n            }\n            else\n            {\n                return true;\n            }\n        }\n\n        internal bool IsSpecialCharacter(char ch)\n        {\n            return _startChars.Contains(ch.ToString()) || _endChars.Contains(ch.ToString());\n        }\n\n        internal bool StartsEscapeSequence(char ch)\n        {","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Xaml/Parser/SpecialBracketCharacters.cs#L62-L98","documentation":"IsValidBracketCharacter throws when either the opening or closing bracket character is a letter, digit, or whitespace. Bracket characters are markup delimiters and must be unambiguous symbols; alphanumeric or whitespace characters would collide with normal attribute text during tokenization.","triggerScenarios":"Tokenize processes a bracket dictionary containing entries like ['a']='b', ['1']='2', or whitespace keys/values; char.IsLetterOrDigit or char.IsWhiteSpace returns true for either character.","commonSituations":"Attempted use of word-like or space-delimited custom escapes in XAML attributes, e.g. trying to use a space or a letter as the custom bracket delimiter.","solutions":["Replace any alphanumeric character in the pair with a punctuation symbol (e.g. '[', ']', '<', '>', '|')","Strip whitespace from configured delimiter characters before registering","Validate the pair with char.IsLetterOrDigit/IsWhiteSpace checks before calling into the parser"],"exampleFix":"// before\nparser.AddBracketCharacters('a', 'b');\n// after\nparser.AddBracketCharacters('<', '>');","handlingStrategy":"validation","validationCode":"bool IsSymbolic(char c) => !char.IsLetterOrDigit(c) && !char.IsWhiteSpace(c);","typeGuard":null,"tryCatchPattern":"try { tokenize(map); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"alpha-numeric\")) { /* sanitize map: drop letter/digit/space entries */ }","preventionTips":["Restrict delimiters to punctuation symbols","Sanitize configuration input by trimming and rejecting letters/digits/spaces"],"tags":["wpf","xaml","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}