Skip to content

Commit 4b7f8b0

Browse files
author
Matthias Gessinger
committed
Explicitly check for existence of links before formatting
1 parent 1400087 commit 4b7f8b0

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/Client/src/Asp.Versioning.Http.Client/net#.0/ILoggerExtensions.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal static void ApiVersionDeprecated(
1919
SunsetPolicy sunsetPolicy )
2020
{
2121
var sunsetDate = FormatDate( sunsetPolicy.Date );
22-
var additionalInfo = FormatLinks( sunsetPolicy.Links );
22+
var additionalInfo = FormatLinks( sunsetPolicy );
2323

2424
ApiVersionDeprecated(
2525
logger,
@@ -46,7 +46,7 @@ internal static void NewApiVersionAvailable(
4646
SunsetPolicy sunsetPolicy )
4747
{
4848
var sunsetDate = FormatDate( sunsetPolicy.Date );
49-
var additionalInfo = FormatLinks( sunsetPolicy.Links );
49+
var additionalInfo = FormatLinks( sunsetPolicy );
5050

5151
NewApiVersionAvailable(
5252
logger,
@@ -70,6 +70,16 @@ static partial void NewApiVersionAvailable(
7070
private static string FormatDate( DateTimeOffset? date ) =>
7171
date.HasValue ? date.Value.ToString( CultureInfo.CurrentCulture ) : "<unspecified>";
7272

73+
private static string[] FormatLinks( SunsetPolicy sunsetPolicy )
74+
{
75+
if ( !sunsetPolicy.HasLinks )
76+
{
77+
return [];
78+
}
79+
80+
return FormatLinks( sunsetPolicy.Links );
81+
}
82+
7383
private static string[] FormatLinks( IList<LinkHeaderValue> links )
7484
{
7585
// <Title> (<Language>[,<Language>]): <Url>

0 commit comments

Comments
 (0)