Skip to content

Commit ed13b31

Browse files
Addressed potential encoding and type mapping issues
- Fixed potential XML encoding issue by explicitly escaping formatted date strings - Fixed potential invalid casting to `bool` by explicitly checking for the value being equal to `true` instead - Fixed potential DataTable mapping issue by adding null coalescing operator after `Nullable.GetType` check
1 parent a627181 commit ed13b31

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

‎src/MiniExcel.OpenXml/Templates/OpenXmlTemplate.Impl.cs‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -823,13 +823,18 @@ private async Task<GenerateCellValuesContext> GenerateCellValuesAsync(
823823
private static string GetFormattedValue(PropertyInfo? propInfo, object? cellValue, Type? type, CultureInfo culture)
824824
{
825825
string? cellValueStr;
826-
if (type == typeof(bool))
826+
if (cellValue is null or DBNull)
827827
{
828-
cellValueStr = (bool)cellValue! ? "1" : "0";
828+
cellValueStr = "";
829+
}
830+
else if (type == typeof(bool))
831+
{
832+
cellValueStr = cellValue is true ? "1" : "0";
829833
}
830834
else if (type == typeof(DateTime))
831835
{
832-
cellValueStr = ConvertToDateTimeString(propInfo, cellValue, culture);
836+
var date = ConvertToDateTimeString(propInfo, cellValue, culture);
837+
cellValueStr = XmlHelper.EncodeXml(date);
833838
}
834839
else if (type?.IsEnum is true)
835840
{
@@ -1379,7 +1384,7 @@ private void UpdateDimensionAndGetRowsInfo(IDictionary<string, object?> inputMap
13791384
//maxRowIndexDiff = dt.Rows.Count <= 1 ? 0 : dt.Rows.Count-1;
13801385
xRowInfo.PropsMap = dt.Columns.Cast<DataColumn>().ToDictionary(col =>
13811386
col.ColumnName,
1382-
col => new MemberInfo { UnderlyingMemberType = Nullable.GetUnderlyingType(col.DataType) }
1387+
col => new MemberInfo { UnderlyingMemberType = Nullable.GetUnderlyingType(col.DataType) ?? col.DataType }
13831388
);
13841389
}
13851390

0 commit comments

Comments
 (0)