From f0e5ada223d9dbd7d8de5ffa785086fb1faf3d6e Mon Sep 17 00:00:00 2001 From: Michael Klement Date: Fri, 7 Dec 2018 21:02:01 -0500 Subject: [PATCH 01/12] Fixes #6994 - Allows use of 'name' as an alias for 'label' in calculated properties - Allows specifying a 'width' value as an integer as well as a string --- .vscode/launch.json | 4 ++-- .../commands/utility/convert-HTML.cs | 14 +++++++++++--- .../ConvertTo-Html.Tests.ps1 | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 4ba261df08c..e8c178134c2 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -6,10 +6,10 @@ "type": "coreclr", "request": "launch", "justMyCode": false, - "stopAtEntry": true, + "stopAtEntry": false, "program": "${workspaceRoot}/debug/pwsh", "preLaunchTask": "Build", - "externalConsole": true, + "console": "integratedTerminal", "cwd": "${workspaceRoot}" }, { diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/convert-HTML.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/convert-HTML.cs index 34f55b0d2d5..fda61e2d08f 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/convert-HTML.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/convert-HTML.cs @@ -300,9 +300,14 @@ internal class ConvertHTMLExpressionParameterDefinition : CommandParameterDefini protected override void SetEntries() { this.hashEntries.Add(new ExpressionEntryDefinition()); - this.hashEntries.Add(new HashtableEntryDefinition(ConvertHTMLParameterDefinitionKeys.LabelEntryKey, new Type[] { typeof(string) })); + // Accept "label" and "name" interchangeably. + // Note: We can't just use `new NameEntryDefinition()`, because the latter uses "name" + // as the key, whereas this cmdlet expects 'label'. That is, this cmdlet's logic is reversed: + // "label" is used as the primary key and "name" as a secondary name. + this.hashEntries.Add(new HashtableEntryDefinition(ConvertHTMLParameterDefinitionKeys.LabelEntryKey, new string[] { NameEntryDefinition.NameEntryKey }, new Type[] { typeof(string) }, false)); this.hashEntries.Add(new HashtableEntryDefinition(ConvertHTMLParameterDefinitionKeys.AlignmentEntryKey, new Type[] { typeof(string) })); - this.hashEntries.Add(new HashtableEntryDefinition(ConvertHTMLParameterDefinitionKeys.WidthEntryKey, new Type[] { typeof(string) })); + // Note: We accept "width" as either string or int. + this.hashEntries.Add(new HashtableEntryDefinition(ConvertHTMLParameterDefinitionKeys.WidthEntryKey, new Type[] { typeof(string), typeof(int) })); } } @@ -335,7 +340,10 @@ private void InitializeResolvedNameMshParameters() { string label = p.GetEntry(ConvertHTMLParameterDefinitionKeys.LabelEntryKey) as string; string alignment = p.GetEntry(ConvertHTMLParameterDefinitionKeys.AlignmentEntryKey) as string; - string width = p.GetEntry(ConvertHTMLParameterDefinitionKeys.WidthEntryKey) as string; + // Accept the width both as a string and as an int. + string width; + int? widthNum = p.GetEntry(ConvertHTMLParameterDefinitionKeys.WidthEntryKey) as int?; + width = widthNum != null ? widthNum.Value.ToString() : p.GetEntry(ConvertHTMLParameterDefinitionKeys.WidthEntryKey) as string; PSPropertyExpression ex = p.GetEntry(FormatParameterDefinitionKeys.ExpressionEntryKey) as PSPropertyExpression; List resolvedNames = ex.ResolveNames(_inputObject); foreach (PSPropertyExpression resolvedName in resolvedNames) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 index 98d566ffbd0..a39efe93597 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 @@ -168,5 +168,21 @@ After the object $returnString = $customObject | ConvertTo-HTML -Transitional | Select-Object -First 1 $returnString | Should -Be '' } + + It "Test ConvertTo-HTML calculated property supports 'name' kay as alias of 'label'" { + $returnString = ($customObject | ConvertTo-Html @{ name = 'AgeRenamed'; e = 'Age'}) -join $newLine + $returnString | Should -Match 'AgeRenamed' + } + + It "Test ConvertTo-HTML calculated property supports integer 'width' entry" { + $returnString = ($customObject | ConvertTo-Html @{ e = 'Age'; width = 10 }) -join $newLine + $returnString | Should -Match '\swidth\s*=\s*(["''])10\1' + } + + It "Test ConvertTo-HTML calculated property supports string 'width' entry" { + $returnString = ($customObject | ConvertTo-Html @{ e = 'Age'; width = '10' }) -join $newLine + $returnString | Should -Match '\swidth\s*=\s*(["''])10\1' + } + } From 12c24f302d689c025e68b3818340735c91e9e9b0 Mon Sep 17 00:00:00 2001 From: Michael Klement Date: Fri, 7 Dec 2018 21:07:40 -0500 Subject: [PATCH 02/12] Reverted accidental change to launch.json --- .vscode/launch.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index e8c178134c2..4ba261df08c 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -6,10 +6,10 @@ "type": "coreclr", "request": "launch", "justMyCode": false, - "stopAtEntry": false, + "stopAtEntry": true, "program": "${workspaceRoot}/debug/pwsh", "preLaunchTask": "Build", - "console": "integratedTerminal", + "externalConsole": true, "cwd": "${workspaceRoot}" }, { From 70a830c4c3a5694854943455bef7e9c002a8bbc2 Mon Sep 17 00:00:00 2001 From: Michael Klement Date: Fri, 7 Dec 2018 21:17:46 -0500 Subject: [PATCH 03/12] CodeFactor style changes --- .../commands/utility/convert-HTML.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/convert-HTML.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/convert-HTML.cs index fda61e2d08f..a6a7a7562db 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/convert-HTML.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/convert-HTML.cs @@ -300,12 +300,14 @@ internal class ConvertHTMLExpressionParameterDefinition : CommandParameterDefini protected override void SetEntries() { this.hashEntries.Add(new ExpressionEntryDefinition()); + // Accept "label" and "name" interchangeably. // Note: We can't just use `new NameEntryDefinition()`, because the latter uses "name" // as the key, whereas this cmdlet expects 'label'. That is, this cmdlet's logic is reversed: // "label" is used as the primary key and "name" as a secondary name. this.hashEntries.Add(new HashtableEntryDefinition(ConvertHTMLParameterDefinitionKeys.LabelEntryKey, new string[] { NameEntryDefinition.NameEntryKey }, new Type[] { typeof(string) }, false)); this.hashEntries.Add(new HashtableEntryDefinition(ConvertHTMLParameterDefinitionKeys.AlignmentEntryKey, new Type[] { typeof(string) })); + // Note: We accept "width" as either string or int. this.hashEntries.Add(new HashtableEntryDefinition(ConvertHTMLParameterDefinitionKeys.WidthEntryKey, new Type[] { typeof(string), typeof(int) })); } @@ -340,6 +342,7 @@ private void InitializeResolvedNameMshParameters() { string label = p.GetEntry(ConvertHTMLParameterDefinitionKeys.LabelEntryKey) as string; string alignment = p.GetEntry(ConvertHTMLParameterDefinitionKeys.AlignmentEntryKey) as string; + // Accept the width both as a string and as an int. string width; int? widthNum = p.GetEntry(ConvertHTMLParameterDefinitionKeys.WidthEntryKey) as int?; From a9b5a9abcf6539d29de7957a267d2b186ce03d50 Mon Sep 17 00:00:00 2001 From: Michael Klement Date: Fri, 7 Dec 2018 21:22:15 -0500 Subject: [PATCH 04/12] Typo --- .../Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 index a39efe93597..6d43467cb04 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 @@ -169,7 +169,7 @@ After the object $returnString | Should -Be '' } - It "Test ConvertTo-HTML calculated property supports 'name' kay as alias of 'label'" { + It "Test ConvertTo-HTML calculated property supports 'name' key as alias of 'label'" { $returnString = ($customObject | ConvertTo-Html @{ name = 'AgeRenamed'; e = 'Age'}) -join $newLine $returnString | Should -Match 'AgeRenamed' } From 8e5cb3a5726d382cab725cec0214a52860718282 Mon Sep 17 00:00:00 2001 From: Michael Klement Date: Fri, 7 Dec 2018 23:47:19 -0500 Subject: [PATCH 05/12] switched to using LabelEntryDefinion() instance --- .../commands/utility/convert-HTML.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/convert-HTML.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/convert-HTML.cs index a6a7a7562db..47403d4b398 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/convert-HTML.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/convert-HTML.cs @@ -300,12 +300,7 @@ internal class ConvertHTMLExpressionParameterDefinition : CommandParameterDefini protected override void SetEntries() { this.hashEntries.Add(new ExpressionEntryDefinition()); - - // Accept "label" and "name" interchangeably. - // Note: We can't just use `new NameEntryDefinition()`, because the latter uses "name" - // as the key, whereas this cmdlet expects 'label'. That is, this cmdlet's logic is reversed: - // "label" is used as the primary key and "name" as a secondary name. - this.hashEntries.Add(new HashtableEntryDefinition(ConvertHTMLParameterDefinitionKeys.LabelEntryKey, new string[] { NameEntryDefinition.NameEntryKey }, new Type[] { typeof(string) }, false)); + this.hashEntries.Add(new LabelEntryDefinition()); this.hashEntries.Add(new HashtableEntryDefinition(ConvertHTMLParameterDefinitionKeys.AlignmentEntryKey, new Type[] { typeof(string) })); // Note: We accept "width" as either string or int. From 144bd99167ac573094f427c6ed17b4a034154dbd Mon Sep 17 00:00:00 2001 From: Michael Klement Date: Thu, 17 Jan 2019 16:17:07 -0500 Subject: [PATCH 06/12] addresses Codacy/PR Quality Review issue --- .../commands/utility/convert-HTML.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/convert-HTML.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/convert-HTML.cs index 47403d4b398..165f9e8de75 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/convert-HTML.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/convert-HTML.cs @@ -301,10 +301,10 @@ protected override void SetEntries() { this.hashEntries.Add(new ExpressionEntryDefinition()); this.hashEntries.Add(new LabelEntryDefinition()); - this.hashEntries.Add(new HashtableEntryDefinition(ConvertHTMLParameterDefinitionKeys.AlignmentEntryKey, new Type[] { typeof(string) })); + this.hashEntries.Add(new HashtableEntryDefinition(ConvertHTMLParameterDefinitionKeys.AlignmentEntryKey, new [] { typeof(string) })); // Note: We accept "width" as either string or int. - this.hashEntries.Add(new HashtableEntryDefinition(ConvertHTMLParameterDefinitionKeys.WidthEntryKey, new Type[] { typeof(string), typeof(int) })); + this.hashEntries.Add(new HashtableEntryDefinition(ConvertHTMLParameterDefinitionKeys.WidthEntryKey, new [] { typeof(string), typeof(int) })); } } From db864f1016ca2e388589a11c389a05084ec0e12d Mon Sep 17 00:00:00 2001 From: Michael Klement Date: Thu, 17 Jan 2019 16:49:14 -0500 Subject: [PATCH 07/12] addresses CodeFactor issues --- .../commands/utility/convert-HTML.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/convert-HTML.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/convert-HTML.cs index 165f9e8de75..cb5b22e241c 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/convert-HTML.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/convert-HTML.cs @@ -301,10 +301,10 @@ protected override void SetEntries() { this.hashEntries.Add(new ExpressionEntryDefinition()); this.hashEntries.Add(new LabelEntryDefinition()); - this.hashEntries.Add(new HashtableEntryDefinition(ConvertHTMLParameterDefinitionKeys.AlignmentEntryKey, new [] { typeof(string) })); + this.hashEntries.Add(new HashtableEntryDefinition(ConvertHTMLParameterDefinitionKeys.AlignmentEntryKey, new[] { typeof(string) })); // Note: We accept "width" as either string or int. - this.hashEntries.Add(new HashtableEntryDefinition(ConvertHTMLParameterDefinitionKeys.WidthEntryKey, new [] { typeof(string), typeof(int) })); + this.hashEntries.Add(new HashtableEntryDefinition(ConvertHTMLParameterDefinitionKeys.WidthEntryKey, new[] { typeof(string), typeof(int) })); } } From 3e1b38a267c5f5a4fd186305bc59892a37d82134 Mon Sep 17 00:00:00 2001 From: Michael Klement Date: Thu, 17 Jan 2019 18:04:00 -0500 Subject: [PATCH 08/12] resolves merge conflict --- .../ConvertTo-Html.Tests.ps1 | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 index 6d43467cb04..674205cd29e 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 @@ -184,5 +184,13 @@ After the object $returnString | Should -Match '\swidth\s*=\s*(["''])10\1' } -} + It "Test ConvertTo-HTML supports scriptblock-based calculated properties: by hashtable"{ + $returnString = ($customObject | ConvertTo-HTML @{ l='NewAge'; e={ $_.Age + 1 } }) -join $newLine + $returnString | Should -Match '\b43\b' + } + It "Test ConvertTo-HTML supports scriptblock-based calculated properties: directly"{ + $returnString = ($customObject | ConvertTo-HTML { $_.Age + 1 }) -join $newLine + $returnString | Should -Match '\b43\b' + } +} From b993fadeee2aa950fd7021f743432732abeb4cc4 Mon Sep 17 00:00:00 2001 From: Michael Klement Date: Thu, 17 Jan 2019 18:09:47 -0500 Subject: [PATCH 09/12] resolves merge conflict --- .../ConvertTo-Html.Tests.ps1 | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 index 674205cd29e..d4ee10861e3 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 @@ -169,6 +169,16 @@ After the object $returnString | Should -Be '' } + It "Test ConvertTo-HTML supports scriptblock-based calculated properties: by hashtable"{ + $returnString = ($customObject | ConvertTo-HTML @{ l='NewAge'; e={ $_.Age + 1 } }) -join $newLine + $returnString | Should -Match '\b43\b' + } + + It "Test ConvertTo-HTML supports scriptblock-based calculated properties: directly"{ + $returnString = ($customObject | ConvertTo-HTML { $_.Age + 1 }) -join $newLine + $returnString | Should -Match '\b43\b' + } + It "Test ConvertTo-HTML calculated property supports 'name' key as alias of 'label'" { $returnString = ($customObject | ConvertTo-Html @{ name = 'AgeRenamed'; e = 'Age'}) -join $newLine $returnString | Should -Match 'AgeRenamed' @@ -184,13 +194,4 @@ After the object $returnString | Should -Match '\swidth\s*=\s*(["''])10\1' } - It "Test ConvertTo-HTML supports scriptblock-based calculated properties: by hashtable"{ - $returnString = ($customObject | ConvertTo-HTML @{ l='NewAge'; e={ $_.Age + 1 } }) -join $newLine - $returnString | Should -Match '\b43\b' - } - - It "Test ConvertTo-HTML supports scriptblock-based calculated properties: directly"{ - $returnString = ($customObject | ConvertTo-HTML { $_.Age + 1 }) -join $newLine - $returnString | Should -Match '\b43\b' - } } From 529fb98c14f7b8907646e8f16aeeeedcc48ab9ef Mon Sep 17 00:00:00 2001 From: Michael Klement Date: Thu, 17 Jan 2019 18:16:16 -0500 Subject: [PATCH 10/12] ??? --- .../ConvertTo-Html.Tests.ps1 | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 index d4ee10861e3..4afd2274050 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 @@ -169,16 +169,6 @@ After the object $returnString | Should -Be '' } - It "Test ConvertTo-HTML supports scriptblock-based calculated properties: by hashtable"{ - $returnString = ($customObject | ConvertTo-HTML @{ l='NewAge'; e={ $_.Age + 1 } }) -join $newLine - $returnString | Should -Match '\b43\b' - } - - It "Test ConvertTo-HTML supports scriptblock-based calculated properties: directly"{ - $returnString = ($customObject | ConvertTo-HTML { $_.Age + 1 }) -join $newLine - $returnString | Should -Match '\b43\b' - } - It "Test ConvertTo-HTML calculated property supports 'name' key as alias of 'label'" { $returnString = ($customObject | ConvertTo-Html @{ name = 'AgeRenamed'; e = 'Age'}) -join $newLine $returnString | Should -Match 'AgeRenamed' From d3a697572c5314c3a048ab14d2358594b8dda1ed Mon Sep 17 00:00:00 2001 From: Michael Klement Date: Thu, 17 Jan 2019 18:18:07 -0500 Subject: [PATCH 11/12] resolves merge conflict --- .../ConvertTo-Html.Tests.ps1 | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 index 4afd2274050..d4ee10861e3 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 @@ -169,6 +169,16 @@ After the object $returnString | Should -Be '' } + It "Test ConvertTo-HTML supports scriptblock-based calculated properties: by hashtable"{ + $returnString = ($customObject | ConvertTo-HTML @{ l='NewAge'; e={ $_.Age + 1 } }) -join $newLine + $returnString | Should -Match '\b43\b' + } + + It "Test ConvertTo-HTML supports scriptblock-based calculated properties: directly"{ + $returnString = ($customObject | ConvertTo-HTML { $_.Age + 1 }) -join $newLine + $returnString | Should -Match '\b43\b' + } + It "Test ConvertTo-HTML calculated property supports 'name' key as alias of 'label'" { $returnString = ($customObject | ConvertTo-Html @{ name = 'AgeRenamed'; e = 'Age'}) -join $newLine $returnString | Should -Match 'AgeRenamed' From 70614e25050185c85faf24530e4beb2ff482d5c0 Mon Sep 17 00:00:00 2001 From: Michael Klement Date: Thu, 17 Jan 2019 18:20:16 -0500 Subject: [PATCH 12/12] resolves merge conflict --- .../Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 index d4ee10861e3..31a6d883684 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Html.Tests.ps1 @@ -169,12 +169,12 @@ After the object $returnString | Should -Be '' } - It "Test ConvertTo-HTML supports scriptblock-based calculated properties: by hashtable"{ + It "Test ConvertTo-HTML supports scriptblock-based calculated properties: by hashtable" { $returnString = ($customObject | ConvertTo-HTML @{ l='NewAge'; e={ $_.Age + 1 } }) -join $newLine $returnString | Should -Match '\b43\b' } - It "Test ConvertTo-HTML supports scriptblock-based calculated properties: directly"{ + It "Test ConvertTo-HTML supports scriptblock-based calculated properties: directly" { $returnString = ($customObject | ConvertTo-HTML { $_.Age + 1 }) -join $newLine $returnString | Should -Match '\b43\b' }