Fix class searcher to ignore hidden properties (#7188)

This commit is contained in:
Steve Lee
2018-06-28 23:29:12 -07:00
committed by Dongbo Wang
parent c83e0e8462
commit 3cc9d26bc2
2 changed files with 25 additions and 2 deletions
@@ -296,8 +296,7 @@ namespace System.Management.Automation
foreach (var member in statement.Members)
{
PropertyMemberAst propAst = member as PropertyMemberAst;
if (propAst != null)
if (member is PropertyMemberAst propAst && !propAst.PropertyAttributes.HasFlag(PropertyAttributes.Hidden))
{
Dbg.Assert(propAst.Name != null, "PropName cannot be null");
Dbg.Assert(propAst.PropertyType != null, "PropertyType cannot be null");
@@ -295,6 +295,14 @@ Describe "Get-Help should find pattern help files" -Tags "CI" {
Remove-Item $helpFilePath2 -Force -ErrorAction SilentlyContinue
}
BeforeEach {
$currentPSModulePath = $env:PSModulePath
}
AfterEach {
$env:PSModulePath = $currentPSModulePath
}
$testcases = @(
@{command = {Get-Help about_testCas?1}; testname = "test ? pattern"; result = "about_test1"}
@{command = {Get-Help about_testCase.?}; testname = "test ? pattern with dot"; result = "about_test2"}
@@ -309,6 +317,22 @@ Describe "Get-Help should find pattern help files" -Tags "CI" {
)
$command.Invoke() | Should -Be $result
}
It "Get-Help should fail expectedly searching for class help with hidden members" {
$testModule = @'
class foo
{
hidden static $monthNames = @('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun','Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')
}
'@
$modulesFolder = Join-Path $TestDrive "Modules"
$modulePath = Join-Path $modulesFolder "TestModule"
New-Item -ItemType Directory -Path $modulePath -Force > $null
Set-Content -Path (Join-Path $modulePath "TestModule.psm1") -Value $testModule
$env:PSModulePath += [System.IO.Path]::PathSeparator + $modulesFolder
{ Get-Help -Category Class -Name foo -ErrorAction Stop } | Should -Throw -ErrorId "HelpNotFound,Microsoft.PowerShell.Commands.GetHelpCommand"
}
}
Describe "Get-Help should find pattern alias" -Tags "CI" {