From 56163f34dded07fd38c76248e7503d837c2ea7b9 Mon Sep 17 00:00:00 2001 From: Anam Navied Date: Thu, 4 Aug 2022 14:00:34 -0400 Subject: [PATCH 1/2] for PSScriptInfo metadata not assume first line will be empty line and can be ignored --- src/code/PSScriptMetadata.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/code/PSScriptMetadata.cs b/src/code/PSScriptMetadata.cs index f5cadb1ed..8ce8d0360 100644 --- a/src/code/PSScriptMetadata.cs +++ b/src/code/PSScriptMetadata.cs @@ -254,7 +254,7 @@ value continued string keyName = ""; string value = ""; - for (int i = 1; i < commentLines.Length; i++) + for (int i = 0; i < commentLines.Length; i++) { string line = commentLines[i]; From 04c71008223cff4bed56bba91e3e59aa4da35542 Mon Sep 17 00:00:00 2001 From: Anam Navied Date: Thu, 4 Aug 2022 16:23:21 -0400 Subject: [PATCH 2/2] add test scripts without empty lines --- test/TestPSScriptFileInfo.Tests.ps1 | 14 +++++++++++ ...tWithoutEmptyLinesBetweenCommentBlocks.ps1 | 24 +++++++++++++++++++ .../ScriptWithoutEmptyLinesInMetadata.ps1 | 23 ++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 test/testFiles/testScripts/ScriptWithoutEmptyLinesBetweenCommentBlocks.ps1 create mode 100644 test/testFiles/testScripts/ScriptWithoutEmptyLinesInMetadata.ps1 diff --git a/test/TestPSScriptFileInfo.Tests.ps1 b/test/TestPSScriptFileInfo.Tests.ps1 index 30adae47b..eb1079c22 100644 --- a/test/TestPSScriptFileInfo.Tests.ps1 +++ b/test/TestPSScriptFileInfo.Tests.ps1 @@ -57,4 +57,18 @@ Describe "Test Test-PSScriptFileInfo" { Test-PSScriptFileInfo $scriptFilePath | Should -Be $false } + + It "determine script without empty lines in PSScriptInfo comment content is valid" { + $scriptName = "ScriptWithoutEmptyLinesInMetadata.ps1" + $scriptFilePath = Join-Path $script:testScriptsFolderPath -ChildPath $scriptName + + Test-PSScriptFileInfo $scriptFilePath | Should -Be $true + } + + It "determine script without empty lines between comment blocks is valid" { + $scriptName = "ScriptWithoutEmptyLinesBetweenCommentBlocks.ps1" + $scriptFilePath = Join-Path $script:testScriptsFolderPath -ChildPath $scriptName + + Test-PSScriptFileInfo $scriptFilePath | Should -Be $true + } } diff --git a/test/testFiles/testScripts/ScriptWithoutEmptyLinesBetweenCommentBlocks.ps1 b/test/testFiles/testScripts/ScriptWithoutEmptyLinesBetweenCommentBlocks.ps1 new file mode 100644 index 000000000..8d8d2aa88 --- /dev/null +++ b/test/testFiles/testScripts/ScriptWithoutEmptyLinesBetweenCommentBlocks.ps1 @@ -0,0 +1,24 @@ + +<#PSScriptInfo +.VERSION 1.0 +.GUID 3951be04-bd06-4337-8dc3-a620bf539fbd +.AUTHOR annavied +.COMPANYNAME +.COPYRIGHT +.TAGS +.LICENSEURI +.PROJECTURI +.ICONURI +.EXTERNALMODULEDEPENDENCIES +.REQUIREDSCRIPTS +.EXTERNALSCRIPTDEPENDENCIES +.RELEASENOTES +.PRIVATEDATA +#> +<# + +.DESCRIPTION + this is a test for a script that will be published remotely + +#> +Param() diff --git a/test/testFiles/testScripts/ScriptWithoutEmptyLinesInMetadata.ps1 b/test/testFiles/testScripts/ScriptWithoutEmptyLinesInMetadata.ps1 new file mode 100644 index 000000000..2b28db61f --- /dev/null +++ b/test/testFiles/testScripts/ScriptWithoutEmptyLinesInMetadata.ps1 @@ -0,0 +1,23 @@ + +<#PSScriptInfo +.VERSION 1.0 +.GUID 3951be04-bd06-4337-8dc3-a620bf539fbd +.AUTHOR annavied +.COMPANYNAME +.COPYRIGHT +.TAGS +.LICENSEURI +.PROJECTURI +.ICONURI +.EXTERNALMODULEDEPENDENCIES +.REQUIREDSCRIPTS +.EXTERNALSCRIPTDEPENDENCIES +.RELEASENOTES +.PRIVATEDATA +#> + +<# +.DESCRIPTION + this is a test for a script that will be published remotely +#> +Param()