Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix script parse whitespace #1457

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()