Skip to content

Commit

Permalink
Handle CultureNotFoundException in AssemblyNameInfoFuzzer, fixes dotn…
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsitnik authored Sep 20, 2024
1 parent 89f245e commit 68b90ac
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Buffers;
using System.Globalization;
using System.Reflection.Metadata;
using System.Runtime.InteropServices;
using System.Text;
Expand Down Expand Up @@ -41,6 +42,19 @@ private static void Test(Span<char> span)
Assert.Equal(fromTryParse.Version, fromParse.Version);
Assert.SequenceEqual(fromTryParse.PublicKeyOrToken.AsSpan(), fromParse.PublicKeyOrToken.AsSpan());

if (!string.IsNullOrEmpty(fromParse.CultureName))
{
try
{
_ = CultureInfo.GetCultureInfo(fromParse.CultureName);
}
catch (CultureNotFoundException)
{
// ToAssemblyName would try to create such a culture and fail.
return;
}
}

Assert.Equal(fromTryParse.ToAssemblyName().Name, fromParse.ToAssemblyName().Name);
Assert.Equal(fromTryParse.ToAssemblyName().Version, fromParse.ToAssemblyName().Version);
Assert.Equal(fromTryParse.ToAssemblyName().ContentType, fromParse.ToAssemblyName().ContentType);
Expand Down

0 comments on commit 68b90ac

Please sign in to comment.