{"record":{"id":"54f697bee0df169a","repo":"iOfficeAI/OfficeCLI","slug":"invalid-data-uri-missing-comma-separator","errorCode":null,"errorMessage":"Invalid data URI: missing comma separator","messagePattern":"Invalid data URI: missing comma separator","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/FileSource.cs","lineNumber":132,"sourceCode":"        // Try extension from URL path\n        var uri = new Uri(url);\n        var ext = Path.GetExtension(uri.AbsolutePath).ToLowerInvariant();\n\n        // Fallback: infer from content-type header\n        if (string.IsNullOrEmpty(ext))\n        {\n            var mime = response.Content.Headers.ContentType?.MediaType;\n            ext = MimeToExtension(mime);\n        }\n\n        return (new MemoryStream(bytes), ext);\n    }\n\n    private static (MemoryStream, string) ResolveDataUri(string dataUri)\n    {\n        var commaIdx = dataUri.IndexOf(',');\n        if (commaIdx < 0)\n            throw new ArgumentException(\"Invalid data URI: missing comma separator\");\n\n        var header = dataUri[..commaIdx];\n        var data = dataUri[(commaIdx + 1)..];\n\n        if (!header.Contains(\"base64\", StringComparison.OrdinalIgnoreCase))\n            throw new ArgumentException(\"Only base64-encoded data URIs are supported\");\n\n        var mimeStart = header.IndexOf(':') + 1;\n        var mimeEnd = header.IndexOf(';');\n        var mime = mimeEnd > mimeStart ? header[mimeStart..mimeEnd] : header[mimeStart..];\n\n        var ext = MimeToExtension(mime);\n        return (new MemoryStream(Convert.FromBase64String(data)), ext);\n    }\n\n    private static string MimeToExtension(string? mime)\n    {\n        if (string.IsNullOrEmpty(mime)) return \"\";","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/FileSource.cs#L114-L150","documentation":"Thrown by FileSource.ResolveDataUri when a data: URI has no comma separating the header from the payload. RFC 2397 data URIs are shaped 'data:[<mediatype>][;base64],<data>'; without the comma the payload cannot be located.","triggerScenarios":"Calling FileSource.Resolve with a string starting with 'data:' (case-insensitive) that contains no ',' character. IndexOf(',') returns -1 and the guard throws.","commonSituations":"Truncated/pasted data URI missing the payload; a data: URL built by string concatenation that dropped the comma; a base64 string passed without the data: prefix wrapper correctly.","solutions":["Ensure the data URI is well-formed: data:<mime>;base64,<payload>.","Use a URI/data-URI builder rather than hand-concatenating.","If you only have raw base64, add the proper 'data:<mime>;base64,' prefix including the comma."],"exampleFix":"// before\nFileSource.Resolve(\"data:image/png;base64\"); // missing ,<payload>\n// after\nFileSource.Resolve($\"data:image/png;base64,{base64Payload}\");","handlingStrategy":"validation","validationCode":"static bool IsPlausibleDataUri(string s) =>\n    s.StartsWith(\"data:\", StringComparison.OrdinalIgnoreCase) && s.Contains(',');","typeGuard":"static bool LooksLikeDataUri(string s) => s.StartsWith(\"data:\", StringComparison.OrdinalIgnoreCase) && s.IndexOf(',') > 4;","tryCatchPattern":"try { var r = FileSource.Resolve(dataUri); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"missing comma separator\"))\n{ /* rebuild the data URI with a proper header+comma */ }","preventionTips":["Build data URIs with a helper, not string concatenation.","Always include the ',' before the payload."],"tags":["file-source","data-uri","validation"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}