NuGetVersion.TryParseStrict() should return false if it fails to parse #9255
Labels
Functionality:SDK
The NuGet client packages published to nuget.org
help wanted
Considered good issues for community contributions.
Type:Bug
Details about Problem
It seems that NuGetVersion.TryParseStrict() doesn't actually ever return false, which isn't ideal for a "Try" method. The implementation actually does check if it can parse to a SemanticVersion, but always returns true anyways...
https://github.com/NuGet/NuGet.Client/blob/bf9523d7b66f749f8709c8f082944db6a60f9153/src/NuGet.Core/NuGet.Versioning/NuGetVersionFactory.cs#L105-L115
NuGet product used (NuGet.exe | VS UI | Package Manager Console | dotnet.exe):
NuGet.Versioning v5.4.0
Detailed repro steps so we can see the same problem
var isValid1 = NuGetVersion.TryParseStrict("NotAVersion", out var parsed1);
// isValid1 == true, parsed == null
var isValid2 = NuGetVersion.TryParseStrict("", out var parsed2);
// isValid2 == true, parsed == null
var isValid3 = NuGetVersion.TryParseStrict("1.0.0", out var parsed3);
// isValid2 == true, parsed != null
The text was updated successfully, but these errors were encountered: