Skip to content

Commit 7aa3dc8

Browse files
authored
Merge pull request #208 from sfoslund/FixSpecifiedVersionBug
Ignore bundles with invalid version strings
2 parents 126cb23 + bba800e commit 7aa3dc8

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

src/dotnet-core-uninstall/Windows/RegistryQuery.cs

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private static Bundle WrapRegistryKey(RegistryKey registryKey)
100100
return Bundle.From(version, arch, uninstallCommand, displayName);
101101
}
102102

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

112-
// Classify the bundle type
113-
if (displayName.IndexOf("Windows Server", StringComparison.OrdinalIgnoreCase) >= 0)
112+
try
114113
{
115-
return new HostingBundleVersion(versionString, footnote);
114+
// Classify the bundle type
115+
if (displayName.IndexOf("Windows Server", StringComparison.OrdinalIgnoreCase) >= 0)
116+
{
117+
return new HostingBundleVersion(versionString, footnote);
118+
}
119+
else if (displayName.IndexOf("ASP.NET", StringComparison.OrdinalIgnoreCase) >= 0)
120+
{
121+
return new AspNetRuntimeVersion(versionString);
122+
}
123+
else if ((displayName.IndexOf(".NET Core SDK", StringComparison.OrdinalIgnoreCase) >= 0) ||
124+
(displayName.IndexOf("Microsoft .NET SDK", StringComparison.OrdinalIgnoreCase) >= 0) ||
125+
uninstallString.IndexOf("dotnet-dev-win") >= 0)
126+
{
127+
return new SdkVersion(versionString);
128+
}
129+
else if (displayName.IndexOf(".NET Core Runtime", StringComparison.OrdinalIgnoreCase) >= 0 || Regex.IsMatch(displayName, @".*\.NET Core.*Runtime") ||
130+
displayName.IndexOf(".NET Runtime", StringComparison.OrdinalIgnoreCase) >= 0)
131+
{
132+
return new RuntimeVersion(versionString);
133+
}
134+
else
135+
{
136+
return null;
137+
}
116138
}
117-
else if (displayName.IndexOf("ASP.NET", StringComparison.OrdinalIgnoreCase) >= 0)
139+
catch
118140
{
119-
return new AspNetRuntimeVersion(versionString);
120-
}
121-
else if ((displayName.IndexOf(".NET Core SDK", StringComparison.OrdinalIgnoreCase) >= 0) ||
122-
(displayName.IndexOf("Microsoft .NET SDK", StringComparison.OrdinalIgnoreCase) >= 0) ||
123-
uninstallString.IndexOf("dotnet-dev-win") >= 0)
124-
{
125-
return new SdkVersion(versionString);
126-
}
127-
else if (displayName.IndexOf(".NET Core Runtime", StringComparison.OrdinalIgnoreCase) >= 0 || Regex.IsMatch(displayName, @".*\.NET Core.*Runtime") ||
128-
displayName.IndexOf(".NET Runtime", StringComparison.OrdinalIgnoreCase) >= 0)
129-
{
130-
return new RuntimeVersion(versionString);
131-
}
132-
else {
133141
return null;
134142
}
135143
}

test/dotnet-core-uninstall.Tests/Windows/RegistryQueryTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,15 @@ internal void TestIsNetCoreBundleAccept(string input)
5151
.Should()
5252
.BeTrue();
5353
}
54+
55+
[WindowsOnlyTheory]
56+
[InlineData("Microsoft ASP.NET Web Frameworks and Tools VS2015")]
57+
[InlineData("Microsoft .NET Core SDK - rc1 (x86)")]
58+
internal void TestGetBundleVersionReturnsNullOnInvalidDisplayNames(string displayName)
59+
{
60+
RegistryQuery.GetBundleVersion(displayName, string.Empty, string.Empty)
61+
.Should()
62+
.BeNull();
63+
}
5464
}
5565
}

0 commit comments

Comments
 (0)