Skip to content

Commit

Permalink
Merge pull request #208 from sfoslund/FixSpecifiedVersionBug
Browse files Browse the repository at this point in the history
Ignore bundles with invalid version strings
  • Loading branch information
sfoslund authored Oct 13, 2021
2 parents 126cb23 + bba800e commit 7aa3dc8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 19 deletions.
46 changes: 27 additions & 19 deletions src/dotnet-core-uninstall/Windows/RegistryQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private static Bundle WrapRegistryKey(RegistryKey registryKey)
return Bundle.From(version, arch, uninstallCommand, displayName);
}

private static BundleVersion GetBundleVersion(string displayName, string uninstallString, string bundleCachePath)
public static BundleVersion GetBundleVersion(string displayName, string uninstallString, string bundleCachePath)
{
var versionString = Regexes.VersionDisplayNameRegex.Match(displayName)?.Value ?? string.Empty;
var cachePathMatch = Regexes.BundleCachePathRegex.Match(bundleCachePath);
Expand All @@ -109,27 +109,35 @@ private static BundleVersion GetBundleVersion(string displayName, string uninsta
string.Format(LocalizableStrings.HostingBundleFootnoteFormat, displayName, versionString) :
null;

// Classify the bundle type
if (displayName.IndexOf("Windows Server", StringComparison.OrdinalIgnoreCase) >= 0)
try
{
return new HostingBundleVersion(versionString, footnote);
// Classify the bundle type
if (displayName.IndexOf("Windows Server", StringComparison.OrdinalIgnoreCase) >= 0)
{
return new HostingBundleVersion(versionString, footnote);
}
else if (displayName.IndexOf("ASP.NET", StringComparison.OrdinalIgnoreCase) >= 0)
{
return new AspNetRuntimeVersion(versionString);
}
else if ((displayName.IndexOf(".NET Core SDK", StringComparison.OrdinalIgnoreCase) >= 0) ||
(displayName.IndexOf("Microsoft .NET SDK", StringComparison.OrdinalIgnoreCase) >= 0) ||
uninstallString.IndexOf("dotnet-dev-win") >= 0)
{
return new SdkVersion(versionString);
}
else if (displayName.IndexOf(".NET Core Runtime", StringComparison.OrdinalIgnoreCase) >= 0 || Regex.IsMatch(displayName, @".*\.NET Core.*Runtime") ||
displayName.IndexOf(".NET Runtime", StringComparison.OrdinalIgnoreCase) >= 0)
{
return new RuntimeVersion(versionString);
}
else
{
return null;
}
}
else if (displayName.IndexOf("ASP.NET", StringComparison.OrdinalIgnoreCase) >= 0)
catch
{
return new AspNetRuntimeVersion(versionString);
}
else if ((displayName.IndexOf(".NET Core SDK", StringComparison.OrdinalIgnoreCase) >= 0) ||
(displayName.IndexOf("Microsoft .NET SDK", StringComparison.OrdinalIgnoreCase) >= 0) ||
uninstallString.IndexOf("dotnet-dev-win") >= 0)
{
return new SdkVersion(versionString);
}
else if (displayName.IndexOf(".NET Core Runtime", StringComparison.OrdinalIgnoreCase) >= 0 || Regex.IsMatch(displayName, @".*\.NET Core.*Runtime") ||
displayName.IndexOf(".NET Runtime", StringComparison.OrdinalIgnoreCase) >= 0)
{
return new RuntimeVersion(versionString);
}
else {
return null;
}
}
Expand Down
10 changes: 10 additions & 0 deletions test/dotnet-core-uninstall.Tests/Windows/RegistryQueryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,15 @@ internal void TestIsNetCoreBundleAccept(string input)
.Should()
.BeTrue();
}

[WindowsOnlyTheory]
[InlineData("Microsoft ASP.NET Web Frameworks and Tools VS2015")]
[InlineData("Microsoft .NET Core SDK - rc1 (x86)")]
internal void TestGetBundleVersionReturnsNullOnInvalidDisplayNames(string displayName)
{
RegistryQuery.GetBundleVersion(displayName, string.Empty, string.Empty)
.Should()
.BeNull();
}
}
}

0 comments on commit 7aa3dc8

Please sign in to comment.