Skip to content

Commit

Permalink
Bugfix script parse whitespace (#1457)
Browse files Browse the repository at this point in the history
  • Loading branch information
anamnavi authored Oct 25, 2023
1 parent 122cdcb commit 91d5c46
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/code/PSScriptFileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ internal static bool TryParseScriptFileContents(
{
string line = fileContents[i];

if (line.StartsWith("<#PSScriptInfo"))
if (line.Trim().StartsWith("<#PSScriptInfo"))
{
int j = i + 1; // start at the next line
// keep grabbing lines until we get to closing #>
while (j < fileContents.Length)
{
string blockLine = fileContents[j];
psScriptInfoCommentContent.Add(blockLine);
if (blockLine.StartsWith("#>"))
if (blockLine.Trim().StartsWith("#>"))
{

reachedPSScriptInfoCommentEnd = true;
Expand All @@ -157,7 +157,7 @@ internal static bool TryParseScriptFileContents(
return false;
}
}
else if (line.StartsWith("<#"))
else if (line.Trim().StartsWith("<#"))
{
// The next comment block must be the help comment block (containing description)
// keep grabbing lines until we get to closing #>
Expand All @@ -166,7 +166,7 @@ internal static bool TryParseScriptFileContents(
{
string blockLine = fileContents[j];

if (blockLine.StartsWith("#>"))
if (blockLine.Trim().StartsWith("#>"))
{
reachedHelpInfoCommentEnd = true;
i = j + 1;
Expand Down
7 changes: 7 additions & 0 deletions test/PSScriptFileInfoTests/TestPSScriptFile.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,11 @@ Describe "Test Test-PSScriptFileInfo" -tags 'CI' {

Test-PSScriptFileInfo $scriptFilePath | Should -Be $true
}

It "determine script with whitespace before closing comment is valid" {
$scriptName = "ScriptWithWhitespaceBeforeClosingComment.ps1"
$scriptFilePath = Join-Path $script:testScriptsFolderPath -ChildPath $scriptName

Test-PSScriptFileInfo $scriptFilePath | Should -Be $true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

<#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()

0 comments on commit 91d5c46

Please sign in to comment.