Skip to content

Commit b1d8553

Browse files
authored
Merge pull request #514 from serilog-mssql/dev
Release 6.5.1 (2nd attempt)
2 parents 7311915 + 2d38ec3 commit b1d8553

File tree

6 files changed

+46
-3
lines changed

6 files changed

+46
-3
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 6.5.1
2+
* Fixed issue #505: NVarChar Columns with 1 data length gets their values truncated into empty strings (thanks to @Whinarn)
3+
* Updated Microsoft.Data.SqlClient to 5.1.4 to fix CVE-2024-0056 (https://github.com/advisories/GHSA-98g6-xh36-x2p7)
4+
15
# 6.5.0
26
* Implemented #488: Support OpenTelemetry TraceId and SpanId as provided by Serilog core
37
* Include README in NuGet package

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<PackageVersion Include="System.Runtime.Extensions" Version="4.3.1" />
1212
<PackageVersion Include="System.Runtime.InteropServices" Version="4.3.0" />
1313
<PackageVersion Include="System.Text.Encoding.Extensions" Version="4.3.0" />
14-
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.0.1" />
14+
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.1.4" />
1515
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
1616
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
1717
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="6.0.1" />

src/Serilog.Sinks.MSSqlServer/Extensions/StringExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ public static string TruncateOutput(this string value, int dataLength) =>
1212
public static string Truncate(this string value, int maxLength, string suffix)
1313
{
1414
if (value == null) return null;
15+
else if (value.Length <= maxLength) return value;
16+
1517
var suffixLength = suffix?.Length ?? 0;
1618
if (maxLength <= suffixLength) return string.Empty;
1719

1820
var correctedMaxLength = maxLength - suffixLength;
19-
return value.Length <= maxLength ? value : Invariant($"{value.Substring(0, correctedMaxLength)}{suffix}");
21+
return Invariant($"{value.Substring(0, correctedMaxLength)}{suffix}");
2022
}
2123
}
2224
}

src/Serilog.Sinks.MSSqlServer/Serilog.Sinks.MSSqlServer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Description>A Serilog sink that writes events to Microsoft SQL Server and Azure SQL</Description>
5-
<VersionPrefix>6.5.0</VersionPrefix>
5+
<VersionPrefix>6.5.1</VersionPrefix>
66
<Authors>Michiel van Oudheusden;Christian Kadluba;Serilog Contributors</Authors>
77
<TargetFrameworks>netstandard2.0;net462;net472;net6.0</TargetFrameworks>
88
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

test/Serilog.Sinks.MSSqlServer.Tests/Extensions/StringExtensionsTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ public void ReturnTruncatedStringWithSuffix()
6262
Assert.Equal("A simple tes...", truncatedMessage);
6363
}
6464

65+
[Theory]
66+
[InlineData("Abc")]
67+
[InlineData("Ab")]
68+
[InlineData("X")]
69+
[Trait("Bugfix", "#505")]
70+
public void ReturnNonTruncatedShortStringWhenMaxLengthIsLessOrEqualToSuffixLength(string inputMessage)
71+
{
72+
// Act
73+
var nonTruncatedMessage = inputMessage.Truncate(3, "...");
74+
75+
// Assert
76+
Assert.Equal(inputMessage, nonTruncatedMessage);
77+
}
78+
6579
[Fact]
6680
public void ReturnTruncatedStringWithEmptySuffix()
6781
{

test/Serilog.Sinks.MSSqlServer.Tests/Sinks/MSSqlServer/Output/AdditionalColumnDataGeneratorTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,5 +202,28 @@ public void GetAdditionalColumnNameAndValueReturnsTruncatedForCharacterTypesWith
202202
Assert.Equal(columnName, result.Key);
203203
Assert.Equal("Additio...", result.Value);
204204
}
205+
206+
[Fact]
207+
[Trait("Bugfix", "#505")]
208+
public void GetAdditionalColumnNameAndValueReturnsFullStringWithOneDataLength()
209+
{
210+
// Arrange
211+
const string columnName = "AdditionalProperty1";
212+
const string propertyValue = "A";
213+
var additionalColumn = new SqlColumn(columnName, SqlDbType.NVarChar);
214+
additionalColumn.DataLength = 1;
215+
var properties = new Dictionary<string, LogEventPropertyValue>();
216+
_columnSimplePropertyValueResolver.Setup(r => r.GetPropertyValueForColumn(
217+
It.IsAny<SqlColumn>(), It.IsAny<IReadOnlyDictionary<string, LogEventPropertyValue>>()))
218+
.Returns(new KeyValuePair<string, LogEventPropertyValue>(columnName, new ScalarValue(propertyValue)));
219+
220+
// Act
221+
var result = _sut.GetAdditionalColumnNameAndValue(additionalColumn, properties);
222+
223+
// Assert
224+
_columnSimplePropertyValueResolver.Verify(r => r.GetPropertyValueForColumn(additionalColumn, properties), Times.Once);
225+
Assert.Equal(columnName, result.Key);
226+
Assert.Equal(propertyValue, result.Value);
227+
}
205228
}
206229
}

0 commit comments

Comments
 (0)