{"record":{"id":"f7365d83365d3b6c","repo":"iOfficeAI/OfficeCLI","slug":"invalid-data-uri-missing-comma-separator-f7365d","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/ImageSource.cs","lineNumber":122,"sourceCode":"        return false;\n    }\n\n    private static string ContentTypeName(PartTypeInfo type)\n    {\n        if (type == ImagePartType.Png) return \"PNG\";\n        if (type == ImagePartType.Jpeg) return \"JPEG\";\n        if (type == ImagePartType.Gif) return \"GIF\";\n        if (type == ImagePartType.Bmp) return \"BMP\";\n        if (type == ImagePartType.Tiff) return \"TIFF\";\n        return type.ContentType ?? \"unknown\";\n    }\n\n    private static (Stream, PartTypeInfo) ResolveDataUri(string dataUri)\n    {\n        // Format: data:[<mediatype>][;base64],<data>\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]; // e.g. \"data:image/png;base64\"\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        // Extract MIME type\n        var mimeStart = header.IndexOf(':') + 1;\n        var mimeEnd = header.IndexOf(';');\n        var mime = mimeEnd > mimeStart ? header[mimeStart..mimeEnd] : header[mimeStart..];\n\n        var contentType = MimeToContentType(mime);\n        var bytes = Convert.FromBase64String(data);\n        // An empty payload decodes \"successfully\" to zero bytes and would\n        // flow all the way into a 0-byte media part — schema-valid, but the\n        // picture renders broken in Word/PowerPoint. Reject up front, like\n        // the extpart carrier does for empty data.","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/ImageSource.cs#L104-L140","documentation":"Thrown by ImageSource.ResolveDataUri when a data: URI string has no comma character anywhere. The data URI format is 'data:[<mediatype>][;base64],<data>' — the comma separates the metadata header from the payload. A missing comma means the URI is malformed at the syntax level and cannot be parsed regardless of encoding.","triggerScenarios":"Passing a data URI like 'data:image/png;base64' (missing the comma and payload) or 'data:image/png' or any string starting with 'data:' that has no comma. The check is dataUri.IndexOf(',') < 0, so even 'data:' with no further content triggers it.","commonSituations":"A data URI that was truncated during copy-paste or serialization. A template string that was not fully interpolated (the payload variable was empty). A malformed data URI generated by a library bug that omits the comma separator. An agent constructing a data URI from parts but forgetting the comma.","solutions":["Ensure the data URI follows the format 'data:<mediatype>;base64,<base64payload>' with a comma before the encoded data.","Use a standard library to construct data URIs rather than string concatenation.","Validate the data URI string has a comma before passing it to ImageSource.Resolve."],"exampleFix":"// before — missing comma\nadd image src='data:image/png;base64' path='/body'\n\n// after — complete data URI with comma and payload\nadd image src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUg...' path='/body'","handlingStrategy":"validation","validationCode":"// Pre-check data URI has a comma\nif (source.StartsWith(\"data:\", StringComparison.OrdinalIgnoreCase) && !source.Contains(','))\n{\n    Console.Error.WriteLine(\"Invalid data URI: missing comma separator.\");\n    return;\n}\nvar (stream, contentType) = ImageSource.Resolve(source);","typeGuard":null,"tryCatchPattern":"try\n{\n    var (stream, contentType) = ImageSource.Resolve(source);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"missing comma separator\"))\n{\n    // Reconstruct the data URI with the proper format\n}","preventionTips":["Use a data URI construction library rather than string concatenation.","Always include the comma separator when building data URIs: 'data:' + mime + ';base64,' + payload.","Validate the data URI format with a simple Contains(',') check before passing it to Resolve."],"tags":["image","data-uri","malformed-input","validation"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}