Skip to content
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
46 changes: 15 additions & 31 deletions src/System.Management.Automation/engine/InitialSessionState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4250,8 +4250,12 @@ .FORWARDHELPCATEGORY Cmdlet
$PSBoundParameters['Full'] = $true
}

# Set the outputencoding to Console::OutputEncoding. More.com doesn't work well with Unicode.
$outputEncoding=[System.Console]::OutputEncoding
# Nano needs to use Unicode, but Windows and Linux need the default
$OutputEncoding = if ([System.Management.Automation.Platform]::IsNanoServer -or [System.Management.Automation.Platform]::IsIoT) {
[System.Text.Encoding]::Unicode
} else {
[System.Console]::OutputEncoding
}

$help = Get-Help @PSBoundParameters

Expand All @@ -4262,7 +4266,15 @@ .FORWARDHELPCATEGORY Cmdlet
}
else
{
$help | more
# Respect PAGER, use more on Windows, and use less on Linux
$moreCommand,$moreArgs = $env:PAGER -split '\s+'
if ($moreCommand) {
$help | & $moreCommand $moreArgs
} elseif ($IsWindows) {
$help | more.com
} else {
$help | less
}
}
";
}
Expand Down Expand Up @@ -4743,32 +4755,6 @@ internal static SessionStateAliasEntry[] BuiltInAliases
# .Link
# https://go.microsoft.com/fwlink/?LinkID=225750
# .ExternalHelp System.Management.Automation.dll-help.xml
";

internal const string DefaultMoreFunctionText = @"
param([string[]]$paths)
# Nano needs to use Unicode, but Windows and Linux need the default
$OutputEncoding = if ([System.Management.Automation.Platform]::IsNanoServer -or [System.Management.Automation.Platform]::IsIoT) {
[System.Text.Encoding]::Unicode
} else {
[System.Console]::OutputEncoding
}

# Respect PAGER, use more on Windows, and use less on Linux
if (Test-Path env:PAGER) {
$pager,$moreArgs = $env:PAGER -split '\s+'
$moreCommand = (Get-Command -CommandType Application $pager | Select-Object -First 1).Definition
} elseif ($IsWindows) {
$moreCommand = (Get-Command -CommandType Application more | Select-Object -First 1).Definition
} else {
$moreCommand = (Get-Command -CommandType Application less | Select-Object -First 1).Definition
}

if($paths) {
foreach ($file in $paths) {
Get-Content $file | & $moreCommand $moreArgs
}
} else { $input | & $moreCommand $moreArgs }
";

internal const string DefaultSetDriveFunctionText = "Set-Location $MyInvocation.MyCommand.Name";
Expand All @@ -4780,8 +4766,6 @@ internal static SessionStateAliasEntry[] BuiltInAliases
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("prompt", DefaultPromptFunctionText, isProductCode: true),
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("TabExpansion2", s_tabExpansionFunctionText, isProductCode: true),
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("Clear-Host", GetClearHostFunctionText(), isProductCode: true),
// Porting note: we keep more because the function acts correctly on Linux
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("more", DefaultMoreFunctionText, isProductCode: true),
SessionStateFunctionEntry.GetDelayParsedFunctionEntry("help", GetHelpPagingFunctionText(), isProductCode: true),
// Porting note: we remove mkdir on Linux because it is a conflict
#if !UNIX
Expand Down
4 changes: 0 additions & 4 deletions test/powershell/engine/Basic/DefaultCommands.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,4 @@ Describe "Verify approved aliases list" -Tags "CI" {
$result | Write-Host
$result | Should -BeNullOrEmpty
}

It "Should have 'more' as a function" {
Test-Path Function:more | Should -BeTrue
}
}
16 changes: 15 additions & 1 deletion test/powershell/engine/Help/HelpSystem.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function GetCurrentUserHelpRoot {

Describe "Validate that <pshome>/<culture>/default.help.txt is present" -Tags @('CI') {

It "Get-Help returns information about the help system." {
It "Get-Help returns information about the help system" {

$help = Get-Help
$help.Name | Should -Be "default"
Expand All @@ -48,6 +48,20 @@ Describe "Validate that <pshome>/<culture>/default.help.txt is present" -Tags @(
}
}

Describe "Validate that the Help function can Run in strict mode" -Tags @('CI') {

It "Help doesn't fail when strict mode is on" {

$help = & {
# run in nested scope to keep strict mode from affecting other tests
Set-StrictMode -Version Latest
Help
}
# the help function renders the help content as text so just verify that there is content
$help | Should -Not -BeNullOrEmpty
}
}

Describe "Validate that get-help works for CurrentUserScope" -Tags @('CI') {
BeforeAll {
$SavedProgressPreference = $ProgressPreference
Expand Down