Skip to content

Commit 5ff8984

Browse files
authored
Merge pull request #27 from canonical/fix/26
Version parsing: fix error when minor version number is empty
2 parents c423e7f + a63f966 commit 5ff8984

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/Dotnet.Installer.Core/Services/Implementations/ManifestService.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Dotnet.Installer.Core.Services.Implementations;
77

88
public partial class ManifestService : IManifestService
99
{
10-
private static Regex DotnetVersionPattern = new (
10+
private static readonly Regex DotnetVersionPattern = new (
1111
pattern: @"\A(?'major'\d+)(?:\.(?'minor'\d+))?\z");
1212

1313
private static readonly JsonSerializerOptions JsonSerializerOptions = new()
@@ -115,15 +115,15 @@ public async Task Remove(Component component, CancellationToken cancellationToke
115115
var parsedVersion = DotnetVersionPattern.Match(version);
116116

117117
if (!parsedVersion.Success) return null;
118-
if (parsedVersion.Groups.ContainsKey("minor")
118+
if (parsedVersion.Groups["minor"].Success
119119
&& int.Parse(parsedVersion.Groups["minor"].Value) != 0)
120120
{
121121
return null;
122122
}
123123

124-
int majorVersion = int.Parse(parsedVersion.Groups["major"].Value);
124+
var majorVersion = int.Parse(parsedVersion.Groups["major"].Value);
125125

126-
return components.Where(c =>
126+
return components.Where(c =>
127127
c.MajorVersion == majorVersion &&
128128
c.Name.Equals(component, StringComparison.CurrentCultureIgnoreCase))
129129
.MaxBy(c => c.MajorVersion);

0 commit comments

Comments
 (0)