diff --git a/src/System.Management.Automation/engine/PSVersionInfo.cs b/src/System.Management.Automation/engine/PSVersionInfo.cs index 6c724a2132b..99740a44d13 100644 --- a/src/System.Management.Automation/engine/PSVersionInfo.cs +++ b/src/System.Management.Automation/engine/PSVersionInfo.cs @@ -729,7 +729,7 @@ private static bool TryParseVersion(string version, ref VersionResult result) } else { - if (dashIndex == -1) + if (plusIndex == -1) { // Here dashIndex == plusIndex == -1 // No preLabel - preLabel == null; @@ -737,6 +737,13 @@ private static bool TryParseVersion(string version, ref VersionResult result) // Format is 'major.minor.patch' versionSansLabel = version; } + else if (dashIndex == -1) + { + // No PreReleaseLabel: preLabel == null + // Format is 'major.minor.patch+BuildLabel' + buildLabel = version.Substring(plusIndex + 1); + versionSansLabel = version.Substring(0, plusIndex); + } else { // Format is 'major.minor.patch-PreReleaseLabel+BuildLabel' diff --git a/test/powershell/engine/Basic/SemanticVersion.Tests.ps1 b/test/powershell/engine/Basic/SemanticVersion.Tests.ps1 index 3d4227c75f8..c6fbc6af969 100644 --- a/test/powershell/engine/Basic/SemanticVersion.Tests.ps1 +++ b/test/powershell/engine/Basic/SemanticVersion.Tests.ps1 @@ -22,6 +22,22 @@ Describe "SemanticVersion api tests" -Tags 'CI' { $v.BuildLabel | Should -BeNullOrEmpty $v.ToString() | Should -Be "1.0.0" + $v = [SemanticVersion]::new("1.2.3+BLD.a1-xxx.03") + $v.Major | Should -Be 1 + $v.Minor | Should -Be 2 + $v.Patch | Should -Be 3 + $v.PreReleaseLabel | Should -BeNullOrEmpty + $v.BuildLabel | Should -Be "BLD.a1-xxx.03" + $v.ToString() | Should -Be "1.2.3+BLD.a1-xxx.03" + + $v = [SemanticVersion]::new("1.0.0+META") + $v.Major | Should -Be 1 + $v.Minor | Should -Be 0 + $v.Patch | Should -Be 0 + $v.PreReleaseLabel | Should -BeNullOrEmpty + $v.BuildLabel | Should -Be "META" + $v.ToString() | Should -Be "1.0.0+META" + $v = [SemanticVersion]::new("3.0") $v.Major | Should -Be 3 $v.Minor | Should -Be 0