You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public void Test() {
var csvContext = new LINQtoCSV.CsvContext();
string testInput =
"NotNullColumn1,NotNullColumn2" + Environment.NewLine +
"Line1NotNull1,Line1NotNull2"; // Note: All not-null columns have values
csvContext.Read<Data>(this.StreamReaderFromString(testInput));
testInput =
"NotNullColumn" + Environment.NewLine +
"Line1NotNull"; // Note: All not-null columns have values
csvContext.Read<Data2>(this.StreamReaderFromString(testInput));
}
class Data {
[LINQtoCSV.CsvColumn(CanBeNull = false)]
public string NotNullColumn1 { get; set; }
public string ExtraColumn { get; set; }
[LINQtoCSV.CsvColumn(CanBeNull = false)]
public string NotNullColumn2 { get; set; }
}
class Data2 {
[LINQtoCSV.CsvColumn(FieldIndex = 1)] // Force Array.Sort() ordering to expose bug
public string ExtraColumn { get; set; }
[LINQtoCSV.CsvColumn(CanBeNull = false)]
public string NotNullColumn { get; set; }
}
The first read (of class Data) throws: 'In line 2, no value provided for required field or property "Column1" in type "UserQuery+Data"'
(The exact column name it complains about depends on exactly how Array.Sort() sorts in line 224 of file FieldMapper.cs, and for some sorting may not even give an error.)
The second read (of class Data2) throws: 'In line 2, no value provided for required field or property "NotNullColumn" in type "UserQuery+Data2".'
The problem is in FieldMapper.ReadNames() where it destructively copies TypeFieldInfos into m_IndexToInfo array, without taking care to preserve the tail of that array.
Before ReadNames, m_IndexToInfo may look like (in the Data2 example):
ExtraColumn,
NotNullColumn
After ReadNames() m_IndexToInfo is:
NotNullColumn,
NotNullColumn
NotNullColumn is duplicated and ExtraColumn has been deleted.
The duplicate NotNullColumn triggers MissingRequiredFieldException at the very very end of FieldMapper.Reading().
Bug 2:
public void Test() {
var csvContext = new LINQtoCSV.CsvContext();
testInput =
"ExtraColumn,Column" + Environment.NewLine +
"Extra,Value";
var fileDescription = new LINQtoCSV.CsvFileDescription { EnforceCsvColumnAttribute = true, IgnoreUnknownColumns = true
};
csvContext.Read<Bug2>(this.StreamReaderFromString(testInput), fileDescription).Dump();
}
class Bug2 {
[LINQtoCSV.CsvColumn()]
public string Column { get; set; }
}
This throws: 'Index was outside the bounds of the array.' (and NOT wrapped in AggregatedException).
The problem is line 438 of FieldMapper.ReadNames() where the field being checked is using the wrong index (it should be m_IndexToInfo[_mappingIndexes[i]].hasColumnAttribute).
The fixed lines are mostly:
protected List<TypeFieldInfo> m_IndexToInfo = null;
...
m_IndexToInfo = new List<TypeFieldInfo>(nbrTypeFields);
...
m_IndexToInfo.Sort();
...
// Re-order m_IndexToInfo to match the field names
for (int i = 0; i < row.Count; i++) {
if (!_mappingIndexes.ContainsKey(i)) {
continue;
}
TypeFieldInfo tfi = m_NameToInfo[row[i].Value];
m_IndexToInfo.Remove(tfi);
m_IndexToInfo.Insert(_mappingIndexes[i], tfi);
if (m_fileDescription.EnforceCsvColumnAttribute && !tfi.hasColumnAttribute) {
// enforcing column attr, but this field/prop has no column attr.
throw new MissingCsvColumnAttributeException(typeof (T).ToString(), row[i].Value, m_fileName);
}
}
I can create unit tests for these and create a new pull request, are pull requests still being considered?
The text was updated successfully, but these errors were encountered:
This code throws exceptions when it should not:
The first read (of class Data) throws: 'In line 2, no value provided for required field or property "Column1" in type "UserQuery+Data"'
(The exact column name it complains about depends on exactly how Array.Sort() sorts in line 224 of file FieldMapper.cs, and for some sorting may not even give an error.)
The second read (of class Data2) throws: 'In line 2, no value provided for required field or property "NotNullColumn" in type "UserQuery+Data2".'
The problem is in FieldMapper.ReadNames() where it destructively copies TypeFieldInfos into m_IndexToInfo array, without taking care to preserve the tail of that array.
Before ReadNames, m_IndexToInfo may look like (in the Data2 example):
After ReadNames() m_IndexToInfo is:
NotNullColumn is duplicated and ExtraColumn has been deleted.
The duplicate NotNullColumn triggers MissingRequiredFieldException at the very very end of FieldMapper.Reading().
Bug 2:
This throws: 'Index was outside the bounds of the array.' (and NOT wrapped in AggregatedException).
The problem is line 438 of FieldMapper.ReadNames() where the field being checked is using the wrong index (it should be m_IndexToInfo[_mappingIndexes[i]].hasColumnAttribute).
The fixed lines are mostly:
I can create unit tests for these and create a new pull request, are pull requests still being considered?
The text was updated successfully, but these errors were encountered: