Fix base64 deserialization when JSON encoder escapes forward slashes (#1342)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
This commit is contained in:
parent
74622d0c9c
commit
774a1dba35
1 changed files with 710 additions and 48 deletions
|
|
@ -80,6 +80,7 @@ public abstract class ResourceContents
|
|||
string? uri = null;
|
||||
string? mimeType = null;
|
||||
ReadOnlyMemory<byte>? blob = null;
|
||||
ReadOnlyMemory<byte>? decodedBlob = null;
|
||||
string? text = null;
|
||||
JsonObject? meta = null;
|
||||
|
||||
|
|
@ -105,7 +106,14 @@ public abstract class ResourceContents
|
|||
break;
|
||||
|
||||
case "blob":
|
||||
blob = reader.HasValueSequence ? reader.ValueSequence.ToArray() : reader.ValueSpan.ToArray();
|
||||
if (!reader.ValueIsEscaped)
|
||||
{
|
||||
blob = reader.HasValueSequence ? reader.ValueSequence.ToArray() : reader.ValueSpan.ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
decodedBlob = reader.GetBytesFromBase64();
|
||||
}
|
||||
break;
|
||||
|
||||
case "text":
|
||||
|
|
@ -122,6 +130,13 @@ public abstract class ResourceContents
|
|||
}
|
||||
}
|
||||
|
||||
if (decodedBlob is not null)
|
||||
{
|
||||
var blobResource = BlobResourceContents.FromBytes(decodedBlob.Value, uri ?? string.Empty, mimeType);
|
||||
blobResource.Meta = meta;
|
||||
return blobResource;
|
||||
}
|
||||
|
||||
if (blob is not null)
|
||||
{
|
||||
return new BlobResourceContents
|
||||
|
|
|
|||
Loading…
Reference in a new issue