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
2 changes: 1 addition & 1 deletion src/MiniExcel.Csv/CsvReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private string[] Split(string row)
return _config.SplitFn(row);

//this code from S.O : https://stackoverflow.com/a/11365961/9131476
return Regex.Split(row, $"[\t{_config.Seperator}](?=(?:[^\"]|\"[^\"]*\")*$)")
return Regex.Split(row, $"{Regex.Escape(_config.Seperator.ToString())}(?=(?:[^\"]|\"[^\"]*\")*$)")
.Select(s => DoubleQuotesRegexImpl.Replace(s.Replace("\"\"", "\""), ""))
.ToArray();
}
Expand Down
13 changes: 13 additions & 0 deletions tests/MiniExcel.Csv.Tests/Main/MiniExcelCsvTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ public void gb2312_Encoding_Read_Test()
Assert.Equal("世界你好", rows[0].栏位1);
}

[Fact]
public void TabInsideValueIsNotASeparatorTest()
{
using var file = AutoDeletingPath.Create(ExcelType.Csv);
var path = file.ToString();
File.WriteAllText(path, "Name,Note,Qty\nA,hello,1\nB,col1\tcol2,2\n");

var rows = _csvImporter.Query(path, true).ToList();

Assert.Equal("col1\tcol2", rows[1].Note);
Assert.Equal("2", rows[1].Qty);
}

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