mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Fix parsing SemanticVersion build label from version string (#16608)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user