Fix parsing SemanticVersion build label from version string (#16608)

This commit is contained in:
Joey Robichaud
2021-12-17 09:39:26 -08:00
committed by GitHub
parent 3e3c56f674
commit b7ce3c568c
2 changed files with 24 additions and 1 deletions
@@ -729,7 +729,7 @@ namespace System.Management.Automation
}
else
{
if (dashIndex == -1)
if (plusIndex == -1)
{
// Here dashIndex == plusIndex == -1
// No preLabel - preLabel == null;
@@ -737,6 +737,13 @@ namespace System.Management.Automation
// 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'
@@ -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