Skip to content

Commit

Permalink
Fix issue with locating package parts in files that contain absolute …
Browse files Browse the repository at this point in the history
…relation paths.
  • Loading branch information
MarkPflug committed Dec 18, 2024
1 parent 941a264 commit 5f4806c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
24 changes: 24 additions & 0 deletions source/Sylvan.Data.Excel.Tests/CustomTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,30 @@ namespace Sylvan.Data.Excel;

public class CustomTests
{

[Fact]
public void BadSlash()
{
// This file contains package relations that use absolute rooted paths instead of relative paths.
// "/xl/workbook.xml" vs "xl/workbook.xml"
// This was causing the issues with the code that locates the package parts
TestSlash("Data/sample_file_bad.xlsx");
}

[Fact]
public void GoodSlash()
{
TestSlash("Data/sample_file_good.xlsx");
}

void TestSlash(string file)
{
using var reader = ExcelDataReader.Create(file);

var b = reader.TryOpenWorksheet("MasterInvoice_Detailed_XLSX");
Assert.True(b);
}

[Fact]
public void InlineString()
{
Expand Down
Binary file not shown.
Binary file not shown.
5 changes: 1 addition & 4 deletions source/Sylvan.Data.Excel/Xlsx/XlsxWorkbookReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,7 @@ private protected override ref readonly FieldInfo GetFieldValue(int ordinal)
private protected override bool OpenWorksheet(int sheetIdx)
{
var sheetName = sheetInfos[sheetIdx].Part;
// the relationship is recorded as an absolute path
// but the zip entry has a relative name.
sheetName = sheetName.TrimStart('/');
var sheetPart = package.GetEntry(sheetName);
var sheetPart = package.FindEntry(sheetName);
if (sheetPart == null)
return false;

Expand Down

0 comments on commit 5f4806c

Please sign in to comment.