Skip to content

Commit

Permalink
When MultipartBody is serialized the values are generated with CRLF
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinM85 committed May 30, 2024
1 parent 55f7244 commit 8dbcd9e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.9.4] - 2024-05-31

### Changed

- Fix MultipartBody serialization

## [1.9.3] - 2024-05-28

### Changed

- Fix time formatting for other cultures.
- Fix MultipartBody serialization

## [1.9.2] - 2024-05-24

Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Kiota.Abstractions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageProjectUrl>https://aka.ms/kiota/docs</PackageProjectUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<Deterministic>true</Deterministic>
<VersionPrefix>1.9.3</VersionPrefix>
<VersionPrefix>1.9.4</VersionPrefix>
<VersionSuffix></VersionSuffix>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<SignAssembly>false</SignAssembly>
Expand Down
24 changes: 12 additions & 12 deletions src/MultipartBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,13 @@ public void Serialize(ISerializationWriter writer)
{
using var partWriter = RequestAdapter.SerializationWriterFactory.GetSerializationWriter(part.ContentType);
partWriter.WriteObjectValue(string.Empty, parsable);
using var partContent = partWriter.GetSerializedContent();
if(partContent.CanSeek)
partContent.Seek(0, SeekOrigin.Begin);
using var ms = new MemoryStream();
partContent.CopyTo(ms);
writer.WriteByteArrayValue(string.Empty, ms.ToArray());
WriteSerializedContent(writer, partWriter);
}
else if(part.Content is string currentString)
{
using var partWriter = RequestAdapter.SerializationWriterFactory.GetSerializationWriter(part.ContentType);
partWriter.WriteStringValue(string.Empty, currentString);
using var partContent = partWriter.GetSerializedContent();
if(partContent.CanSeek)
partContent.Seek(0, SeekOrigin.Begin);
using var ms = new MemoryStream();
partContent.CopyTo(ms);
writer.WriteByteArrayValue(string.Empty, ms.ToArray());
WriteSerializedContent(writer, partWriter);
}
else if(part.Content is MemoryStream originalMemoryStream)
{
Expand Down Expand Up @@ -191,6 +181,16 @@ private void AddNewLine(ISerializationWriter writer)
writer.WriteStringValue(string.Empty, string.Empty);
}

private void WriteSerializedContent(ISerializationWriter writer, ISerializationWriter partWriter)
{
using var partContent = partWriter.GetSerializedContent();
if(partContent.CanSeek)
partContent.Seek(0, SeekOrigin.Begin);
using var ms = new MemoryStream();
partContent.CopyTo(ms);
writer.WriteByteArrayValue(string.Empty, ms.ToArray());
}

private class Part
{
public Part(string name, object content, string contentType, string? fileName)
Expand Down

0 comments on commit 8dbcd9e

Please sign in to comment.