-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Closed
Labels
Issue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.The issue is fixed.WG-Interactive-HelpSystemhelp infrastructure and formatting of helphelp infrastructure and formatting of help
Description
Reproducible on 6.1.0 and on master b525b1f
Steps to reproduce
$sb = {
<#
.SYNOPSIS
Sample synopsis.
#>
process { }
}
$str = [String]$sb
Set-Item -Path function:private:FunctionFromString -Value $str
(Get-Help FunctionFromString).Synopsis
Set-Item -Path function:private:FunctionFromScriptBlock -Value $sb
(Get-Help FunctionFromScriptBlock).SynopsisExpected behavior
Sample synopsis.
Sample synopsis.
Actual behavior
Sample synopsis.
FunctionFromScriptBlock
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 6.1.0
PSEdition Core
GitCommitId 6.1.0
OS Microsoft Windows 10.0.17134
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0Analysis
The difference between these two cases can be observed in the following block of code:
PowerShell/src/System.Management.Automation/help/HelpCommentsParser.cs
Lines 1145 to 1164 in b525b1f
| else if (ast == rootAst) | |
| { | |
| startTokenIndex = savedStartIndex = 0; | |
| lastTokenIndex = tokens.Length - 1; | |
| } | |
| else | |
| { | |
| // This case should be rare (but common with implicit remoting). | |
| // We have a script block that was used to generate a function like: | |
| // $sb = { } | |
| // set-item function:foo $sb | |
| // help foo | |
| startTokenIndex = savedStartIndex = FirstTokenInExtent(tokens, ast.Extent) - 1; | |
| lastTokenIndex = LastTokenInExtent(tokens, ast.Extent, startTokenIndex); | |
| Diagnostics.Assert(tokens[startTokenIndex + 1].Kind == TokenKind.LCurly, | |
| "Unexpected first token in script block"); | |
| Diagnostics.Assert(tokens[lastTokenIndex].Kind == TokenKind.RCurly, | |
| "Unexpected last token in script block"); | |
| } |
[ScriptBlock] cases are handled by the else statement where the startTokenIndex is being set to the position before script block itself. Changing - 1 to + 1 in the line
| startTokenIndex = savedStartIndex = FirstTokenInExtent(tokens, ast.Extent) - 1; |
solves the problem.
May I prepare a PR for this?
vexx32
Metadata
Metadata
Assignees
Labels
Issue-BugIssue has been identified as a bug in the productIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.The issue is fixed.WG-Interactive-HelpSystemhelp infrastructure and formatting of helphelp infrastructure and formatting of help