From 30b97a5d7c0dff1b1b12acc29cbdc149938da44c Mon Sep 17 00:00:00 2001 From: Michael Klement Date: Tue, 16 May 2017 20:10:03 -0400 Subject: [PATCH] Fix for #3786 (#3793) The appropriate [SemanticVersion] constructor now accepts a [version] instance that has only major and minor components specified, in which case the patch component now defaults to 0. --- src/System.Management.Automation/engine/PSVersionInfo.cs | 4 ++-- test/powershell/engine/SemanticVersion.Tests.ps1 | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/System.Management.Automation/engine/PSVersionInfo.cs b/src/System.Management.Automation/engine/PSVersionInfo.cs index b194becec..bdd9364c5 100644 --- a/src/System.Management.Automation/engine/PSVersionInfo.cs +++ b/src/System.Management.Automation/engine/PSVersionInfo.cs @@ -493,11 +493,11 @@ namespace System.Management.Automation /// The version. public SemanticVersion(Version version) { - if (version.Revision > 0 || version.Build < 0) throw PSTraceSource.NewArgumentException(nameof(version)); + if (version.Revision > 0) throw PSTraceSource.NewArgumentException(nameof(version)); Major = version.Major; Minor = version.Minor; - Patch = version.Build; + Patch = version.Build == -1 ? 0 : version.Build; var psobj = new PSObject(version); var labelNote = psobj.Properties[LabelPropertyName]; if (labelNote != null) diff --git a/test/powershell/engine/SemanticVersion.Tests.ps1 b/test/powershell/engine/SemanticVersion.Tests.ps1 index 34f84a472..40c448e56 100644 --- a/test/powershell/engine/SemanticVersion.Tests.ps1 +++ b/test/powershell/engine/SemanticVersion.Tests.ps1 @@ -50,6 +50,9 @@ Describe "SemanticVersion api tests" -Tags 'CI' { } It "version arg constructor" { + $v = [SemanticVersion]::new([Version]::new(1, 2)) + $v.ToString() | Should Be '1.2.0' + $v = [SemanticVersion]::new([Version]::new(1, 2, 3)) $v.ToString() | Should Be '1.2.3' }