Skip to content

Commit

Permalink
Seek stream from Base64.DecodedToStream to begin (#17132)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Mike Alhayek <[email protected]>
  • Loading branch information
AndreySurkov and MikeAlhayek authored Dec 6, 2024
1 parent ff54b8f commit 9f8423a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/OrchardCore/OrchardCore.Abstractions/Base64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public static Stream DecodedToStream(string base64)
}

memoryStream.Advance(bytesWritten);

memoryStream.Seek(0, SeekOrigin.Begin);

return memoryStream;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ static CommonGeneratorMethods()
Method = serviceProvider => (Func<string, string>)(encoded =>
{
var compressedStream = Base64.DecodedToStream(encoded);
compressedStream.Seek(0, SeekOrigin.Begin);

using var gZip = new GZipStream(compressedStream, CompressionMode.Decompress, leaveOpen: true);

Expand Down
16 changes: 15 additions & 1 deletion test/OrchardCore.Tests/Abstractions/Base64Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,22 @@ public class Base64Tests
[InlineData("SGVsbA==", "Hell")]
[InlineData("SGVsbG8=", "Hello")]
[InlineData("", "")]
public void MergeArrayShouldRespectJsonMergeSettings(string source, string expected)
public void DecodeToStringTest(string source, string expected)
{
Assert.Equal(expected, Base64.FromUTF8Base64String(source));
}

[Theory]
[InlineData("YTw+OmE/", "a<>:a?")]
[InlineData("SGVsbA==", "Hell")]
[InlineData("SGVsbG8=", "Hello")]
[InlineData("", "")]
public void DecodeToStreamTest(string source, string expected)
{
using var stream = Base64.DecodedToStream(source);
using var sr = new StreamReader(stream);
{
Assert.Equal(expected, sr.ReadToEnd());
}
}
}

0 comments on commit 9f8423a

Please sign in to comment.