{"record":{"id":"6f1724acd48425f0","repo":"AvaloniaUI/Avalonia","slug":"could-not-parse-specified-unicode-range-segment","errorCode":null,"errorMessage":"Could not parse specified Unicode range segment.","messagePattern":"Could not parse specified Unicode range segment\\.","errorType":"exception","errorClass":"FormatException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Media/UnicodeRange.cs","lineNumber":147,"sourceCode":"        /// <returns>\n        /// <c>true</c> If given value is inside the range segment, <c>false</c> otherwise.\n        /// </returns>\n        public bool IsInRange(int value)\n        {\n            return Start <= value && value <= End;\n        }\n\n        /// <summary>\n        /// Parses a <see cref=\"UnicodeRangeSegment\"/>.\n        /// </summary>\n        /// <param name=\"s\">The string to parse.</param>\n        /// <returns>The parsed <see cref=\"UnicodeRangeSegment\"/>.</returns>\n        /// <exception cref=\"FormatException\"></exception>\n        public static UnicodeRangeSegment Parse(string s)\n        {\n            if (string.IsNullOrEmpty(s))\n            {\n                throw new FormatException(\"Could not parse specified Unicode range segment.\");\n            }\n\n            var parts = s.Split('-');\n\n            int start, end;\n\n            switch (parts.Length)\n            {\n                case 1:\n                    {\n                        //e.g. U+20, U+3F U+30??\n                        var single = s_regex.Match(parts[0]);\n\n                        if (!single.Success)\n                        {\n                            throw new FormatException(\"Could not parse specified Unicode range segment.\");\n                        }\n","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Media/UnicodeRange.cs#L129-L165","documentation":"Thrown by UnicodeRangeSegment.Parse when the input string s is null or empty. A UnicodeRangeSegment is a single component of a unicode-range (e.g. 'U+20' or 'U+20-7F'); an empty/null segment cannot be parsed and is rejected with a FormatException. This is the entry guard of the segment parser.","triggerScenarios":"Calling UnicodeRangeSegment.Parse(null) or UnicodeRangeSegment.Parse(\"\"), or indirectly when UnicodeRange.Parse splits on commas and a segment (after the line-86 path) is empty — e.g. a trailing comma in 'U+20-7F,' producing an empty segment.","commonSituations":"Malformed unicode-range strings with trailing/leading/double commas; deserialized config with empty segments; user-authored CSS @font-face unicode-range with stray commas.","solutions":["Ensure each comma-separated segment is a valid 'U+XXXX' or 'U+XXXX-YYYY' expression.","Trim and filter out empty segments before parsing: parts.Where(p => !string.IsNullOrWhiteSpace(p)).","Validate the full unicode-range string format before calling Parse."],"exampleFix":"// before\nvar seg = UnicodeRangeSegment.Parse(\"\"); // throws\n// or: UnicodeRange.Parse(\"U+20-7F,\") -> empty trailing segment throws\n\n// after\nvar seg = UnicodeRangeSegment.Parse(\"U+20\");","handlingStrategy":"validation","validationCode":"static UnicodeRangeSegment SafeParseSegment(string s)\n    => string.IsNullOrWhiteSpace(s)\n        ? throw new ArgumentException(\"empty segment\")\n        : UnicodeRangeSegment.Parse(s.Trim());","typeGuard":null,"tryCatchPattern":"try { return UnicodeRangeSegment.Parse(s); }\ncatch (FormatException) { /* skip or default the segment */ }","preventionTips":["Trim and filter empty segments when splitting a unicode-range on commas.","Avoid trailing/leading/double commas in unicode-range strings.","Validate each segment is a valid 'U+XXXX' expression before parsing."],"tags":["unicode","parse","format-exception","avalonia"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}