Skip to content

Commit 1ac0f18

Browse files
author
MPCoreDeveloper
committed
Fix test failures: update version checks and fix JSON parsing with trailing nulls
1 parent ce6c1b5 commit 1ac0f18

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

src/SharpCoreDB.EntityFrameworkCore/USAGE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# SharpCoreDB.EntityFrameworkCore - Usage Guide
22

3-
**Version:** `v1.7.2`
3+
**Version:** `v1.8.0`
44
**Target:** `.NET 10` / `C# 14`
55

66
This guide focuses on the maintained EF Core provider workflow for SharpCoreDB.
77

88
## Install
99

1010
```bash
11-
dotnet add package SharpCoreDB.EntityFrameworkCore --version 1.7.2
11+
dotnet add package SharpCoreDB.EntityFrameworkCore --version 1.8.0
1212
dotnet add package Microsoft.EntityFrameworkCore.Design
1313
```
1414

src/SharpCoreDB/SingleFileTable.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,27 @@ private void EnsureCacheLoaded()
489489
return;
490490
}
491491

492-
var rows = JsonSerializer.Deserialize<List<Dictionary<string, object?>>>(stream);
492+
// Read the stream into bytes and trim trailing null bytes
493+
using var memoryStream = new MemoryStream();
494+
stream.CopyTo(memoryStream);
495+
var jsonBytes = memoryStream.ToArray();
496+
497+
// Trim trailing null bytes
498+
var endIndex = jsonBytes.Length;
499+
while (endIndex > 0 && jsonBytes[endIndex - 1] == 0)
500+
{
501+
endIndex--;
502+
}
503+
504+
if (endIndex == 0)
505+
{
506+
_rowCache = [];
507+
_cacheLoaded = true;
508+
return;
509+
}
510+
511+
var trimmedJsonBytes = jsonBytes.AsSpan(0, endIndex);
512+
var rows = JsonSerializer.Deserialize<List<Dictionary<string, object?>>>(trimmedJsonBytes);
493513
_rowCache = rows?.Select(FromSerializableRow).ToList() ?? [];
494514
_cacheLoaded = true;
495515
}

0 commit comments

Comments
 (0)