Skip to content

.Net: Percent-decode non-base64 data URIs in BinaryContent - #14519

Open
Federico Laurianti (Laurianti) wants to merge 1 commit into
microsoft:mainfrom
Laurianti:fix-binarycontent-percent-decoding
Open

Federico Laurianti (Laurianti) wants to merge 1 commit into
microsoft:mainfrom
Laurianti:fix-binarycontent-percent-decoding

Conversation

@Laurianti

Copy link
Copy Markdown
Contributor

Motivation and Context

BinaryContent built from a non-base64 data URI returned the URI's data as UTF-8 text with the %xx escapes still in it, while RFC 2397, which DataUriParser follows, defines each escape as the octet it names. ImageContent and AudioContent inherit the conversion.

new BinaryContent("data:,A%20brief%20note").Data
// Before: "A%20brief%20note"    Now: "A brief note"

new BinaryContent("data:application/octet-stream,%FF%00%80").Data
// Before: 25 46 46 25 30 30 25 38 30    Now: FF 00 80

Fixes #14518.

Description

  • GetCachedByteArrayContent decodes the escapes to bytes with WebUtility.UrlDecodeToBytes, after escaping + so that it stays a plus. Data without escapes, such as the existing 01-02-03-04 cases, is unchanged.
  • ReturnPercentDecodedOctetsWhenDataIsNotBase64 covers the RFC example, binary octets, an iso-8859-1 octet and a literal +.

Contribution Checklist

Copilot AI balanced review requested due to automatic review settings October 1, 2026 11:06
@semantic-kernel-automation semantic-kernel-automation Bot added .NET Issue or Pull requests regarding .NET code kernel Issues or pull requests impacting the core kernel kernel.core labels Oct 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation matches RFC 2397 semantics and includes focused regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes non-base64 data URI conversion by decoding percent-escaped octets while preserving literal plus signs.

Changes:

  • Percent-decodes non-base64 data URI payloads.
  • Adds coverage for text, binary, charset, and literal-plus cases.
File Description
dotnet/​src/​SemanticKernel.Abstractions/​Contents/​BinaryContent.cs Decodes escaped octets when materializing binary data.
dotnet/​src/​SemanticKernel.UnitTests/​Contents/​BinaryContentTests.cs Verifies expected decoding behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

This branch was successfully deployed

1 active deployment
github-app-auth — bb13ea82 Deployed Oct 1, 2026 by Laurianti via team_check #569
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kernel.core kernel Issues or pull requests impacting the core kernel .NET Issue or Pull requests regarding .NET code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.Net: Bug: BinaryContent does not decode the %xx escapes of a non-base64 data URI

2 participants