镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Microsoft.Data.Sqlite.Core/SqliteBlob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ public override void Write(byte[] buffer, int offset, int count)
/// </param>
public override void Write(ReadOnlySpan<byte> buffer)
{
if (_blob == null)
{
throw new ObjectDisposedException(objectName: null);
}

if (!CanWrite)
{
throw new NotSupportedException(Resources.WriteNotSupported);
Expand Down
19 changes: 19 additions & 0 deletions test/Microsoft.Data.Sqlite.Tests/SqliteBlobTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,25 @@ public void Write_throws_when_disposed()
var ex = Assert.Throws<ObjectDisposedException>(() => stream.Write([3], 0, 1));
}

[Fact]
public void Write_span_throws_when_disposed()
{
var stream = CreateStream();
stream.Dispose();

Assert.Throws<ObjectDisposedException>(() => stream.Write(new ReadOnlySpan<byte>([3])));
Assert.Throws<ObjectDisposedException>(() => stream.Write(ReadOnlySpan<byte>.Empty));
}

[Fact]
public void Read_span_throws_when_disposed()
{
var stream = CreateStream();
stream.Dispose();

Assert.Throws<ObjectDisposedException>(() => stream.Read(new byte[1].AsSpan()));
}

[Fact]
public void Empty_works()
{
Expand Down
Loading