Fix retrieving dynamic parameters from provider even if globbed path returns no results (#15525)

This commit is contained in:
Steve Lee
2021-06-14 11:09:26 -07:00
committed by GitHub
parent f570029986
commit 9aa9a75cad
2 changed files with 9 additions and 5 deletions
@@ -4681,7 +4681,7 @@ namespace System.Management.Automation
}
}
if (providerPath != null)
if (providerInstance != null)
{
// Get the dynamic parameters for the first resolved path
return CopyItemDynamicParameters(providerInstance, providerPath, destination, recurse, newContext);
@@ -4733,10 +4733,6 @@ namespace System.Management.Automation
providerInstance != null,
"Caller should validate providerInstance before calling this method");
Dbg.Diagnostics.Assert(
path != null,
"Caller should validate path before calling this method");
Dbg.Diagnostics.Assert(
context != null,
"Caller should validate context before calling this method");
@@ -256,6 +256,14 @@ Describe "Parameter Binding Tests" -Tags "CI" {
DynamicParamTest -PipelineVariable bar | ForEach-Object { $bar } | Should -Be "hi"
}
It 'Dynamic parameter is found even if globbed path does not exist' {
$guid = New-Guid
# This test verifies that the ErrorRecord is coming from parameter validation on a dynamic parameter
# instead of an error indicating that the dynamic parameter is not found
{ Copy-Item "~\$guid*" -Destination ~ -ToSession $null } | Should -Throw -ErrorId 'ParameterArgumentValidationError'
}
Context "PipelineVariable Behaviour" {
BeforeAll {