Describe the bug
BinaryContent, and so ImageContent and AudioContent, built from a data URI without ;base64 returns the URI's data as UTF-8 text with the %xx escapes still in it. DataUriParser follows RFC 2397, where "the data (as a sequence of octets) is represented using ASCII encoding for octets inside the range of safe URL characters and using the standard %xx hex encoding of URLs for octets outside that range".
To Reproduce
var content = new BinaryContent("data:,A%20brief%20note");
Console.WriteLine(Encoding.UTF8.GetString(content.Data!.Value.Span)); // A%20brief%20note
Data as hex:
data:,A%20brief%20note -> 41 25 32 30 62 72 69 65 66 25 32 30 6E 6F 74 65 ("A%20brief%20note")
data:application/octet-stream,%FF%00%80 -> 25 46 46 25 30 30 25 38 30 ("%FF%00%80")
Expected behavior
A brief note, as in the RFC 2397 example ("The URL data:,A%20brief%20note encodes the text/plain string "A brief note""), and the three octets FF 00 80.
Platform
- Language: C#
- Source: NuGet Microsoft.SemanticKernel.Abstractions 1.80.1, also main at 58ad1a3
- OS: Linux (mcr.microsoft.com/dotnet/sdk:10.0)
Additional context
BinaryContent.GetCachedByteArrayContent returns Encoding.UTF8.GetBytes(parsedDataUri.Data) for non-base64 data. DataUriParser keeps the data escaped (its tests expect A%20brief%20note), so the decoding belongs to the conversion to bytes.
Describe the bug
BinaryContent, and soImageContentandAudioContent, built from a data URI without;base64returns the URI's data as UTF-8 text with the%xxescapes still in it.DataUriParserfollows RFC 2397, where "the data (as a sequence of octets) is represented using ASCII encoding for octets inside the range of safe URL characters and using the standard %xx hex encoding of URLs for octets outside that range".To Reproduce
Dataas hex:Expected behavior
A brief note, as in the RFC 2397 example ("The URLdata:,A%20brief%20noteencodes the text/plain string "A brief note""), and the three octetsFF 00 80.Platform
Additional context
BinaryContent.GetCachedByteArrayContentreturnsEncoding.UTF8.GetBytes(parsedDataUri.Data)for non-base64 data.DataUriParserkeeps the data escaped (its tests expectA%20brief%20note), so the decoding belongs to the conversion to bytes.