Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

DynamicParam fails when there are quoted param values #3189

Copy link
Copy link
@MysticRyuujin

Description

@MysticRyuujin
Issue body actions

Steps to reproduce

Function New-ValidationDynamicParam
{
    [CmdletBinding()]
    [OutputType('System.Management.Automation.RuntimeDefinedParameter')]
    param (
        [Parameter(Mandatory)]
        [ValidateNotNullOrEmpty()]
        [string]$Name,
        [ValidateNotNullOrEmpty()]
        [Parameter(Mandatory)]
        [array]$ValidateSetOptions,
        [Parameter()]
        [switch]$Mandatory = $false,
        [Parameter()]
        [string]$ParameterSetName = '__AllParameterSets',
        [Parameter()]
        [switch]$ValueFromPipeline = $false,
        [Parameter()]
        [switch]$ValueFromPipelineByPropertyName = $false
    )
    $AttribColl = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
    $ParamAttrib = New-Object System.Management.Automation.ParameterAttribute
    $ParamAttrib.Mandatory = $Mandatory.IsPresent
    $ParamAttrib.ParameterSetName = $ParameterSetName
    $ParamAttrib.ValueFromPipeline = $ValueFromPipeline.IsPresent
    $ParamAttrib.ValueFromPipelineByPropertyName = $ValueFromPipelineByPropertyName.IsPresent
    $AttribColl.Add($ParamAttrib)
    $AttribColl.Add((New-Object System.Management.Automation.ValidateSetAttribute($Param.ValidateSetOptions)))
    $RuntimeParam = New-Object System.Management.Automation.RuntimeDefinedParameter($Param.Name, [string], $AttribColl)
    Return $RuntimeParam
}

Function DP-Bug
{
    [CmdletBinding()]
    Param
    (
        [ValidateSet("NoSpace","Yes Space")]
        [string]$Param1
    )

    DynamicParam
    {
        $ParamOptions = @(
            @{
                'Name' = 'Param2';
                'Mandatory' = $True;
                'ValidateSetOptions' = @(
                    'Option 1',
                    'Option 2'
                )
            })
        $RuntimeParamDic = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
        foreach ($Param in $ParamOptions)
        {
            $RuntimeParam = New-ValidationDynamicParam @Param
            $RuntimeParamDic.Add($Param.Name, $RuntimeParam)
        }
        Return $RuntimeParamDic
    }
    begin
    {
        Write-Output "OK"
    }
}

DP-Bug -Param1 NoSpace -<tab>
DP-Bug -Param1 'Yes Space' -<tab>

Expected behavior

DP-Bug -Param1 NoSpace -Param2
DP-Bug -Param1 'Yes Space' -Param2

Actual behavior

DP-Bug -Param1 NoSpace -Param2
DP-Bug -Param1 'Yes Space' -Verbose

Basically, DynamicParam stops tab completing (though it does process and can become a mandatory parameter) if it is proceeded by a parameter value that has spaces/quotes around it. I tried changing the quotes from single to double as well, no change.

Environment data

Name                           Value
----                           -----
PSVersion                      5.0.10586.117
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.10586.117
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    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.Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Interactive-IntelliSensetab completiontab completion

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.