Allow dynamic parameter to be returned even if path matches nothing (#7957)

This commit is contained in:
Steve Lee 2018-10-19 02:44:08 +08:00 committed by Aditya Patwardhan
parent f1e2136a2b
commit 4e5e3900f6
2 changed files with 10 additions and 7 deletions

View file

@ -275,13 +275,7 @@ namespace System.Management.Automation
out provider,
out providerInstance);
if (providerPaths.Count > 0)
{
// Get the dynamic parameters for the first resolved path
return GetContentReaderDynamicParameters(providerInstance, providerPaths[0], newContext);
}
return null;
return GetContentReaderDynamicParameters(providerInstance, path, newContext);
} // GetContentReaderDynamicParameters
/// <summary>

View file

@ -278,6 +278,15 @@ baz
} | Should -Throw -ErrorId "InvalidOperation,Microsoft.PowerShell.Commands.GetContentCommand"
}
It "Should throw ItemNotFound when path matches no files with <variation>" -TestCases @(
@{ variation = "no additional parameters"; params = @{} },
@{ variation = "dynamic parameter" ; params = @{ Raw = $true }}
) {
param($params)
{ Get-Content -Path "/DoesNotExist*.txt" @params -ErrorAction Stop } | Should -Throw -ErrorId "ItemNotFound,Microsoft.PowerShell.Commands.GetContentCommand"
}
Context "Check Get-Content containing multi-byte chars" {
BeforeAll {
$firstLine = "Hello,World"