Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variables in array of values are concatenated in error when parsing #30

Open
HardingChris opened this issue Dec 13, 2022 · 0 comments
Open

Comments

@HardingChris
Copy link

When parsing a DSC resource that contains variables in the array of values for one of the keys, the variable name ends up concatenated with the next member of the array in error.

For example, parsing the ExcludeGroups of the AADConditionalAccessPolicy resource below (additional properties removed for brevity):

Node localhost
    {
        AADConditionalAccessPolicy CA01
        {
            ExcludeGroups = @($env:BreakGlassGroup,$env:MMDServiceAccountGroup,"MSG_DEV_CASpecificExclusion");
        }
    }

Results in parsed results like this:

    "ExcludeGroups":  [
                          "$env:BreakGlassGroup,env:MMDServiceAccountGroup",
                          "MSG_DEV_CASpecificExclusion"
                      ]

Rather than like this:

    "ExcludeGroups":  [
                          "$env:BreakGlassGroup",
                          "$env:MMDServiceAccountGroup",
                          "MSG_DEV_CASpecificExclusion"
                      ]

The problem appears to be with the Do Until loop at row 256 in Modules/DSCParser.psm1:

Do {
    $currentPropertyIndex++
    $ValueToSet += $group[$CurrentPropertyIndex].Content
} until (($group[$CurrentPropertyIndex + 1].Type -eq 'Operator' -and $group[$CurrentPropertyIndex + 1].Content -eq ',') -or $group[$currentPropertyIndex + 1].Type -eq 'GroupEnd')

Because this iterates once through the loop before checking the Until condition, it appends the ',' operator and the content of the following variable before it stops looping.

From testing it looks as though this can be solved by using a While loop instead:

While (-not (($group[$CurrentPropertyIndex + 1].Type -eq 'Operator' -and $group[$CurrentPropertyIndex + 1].Content -eq ',') -or $group[$currentPropertyIndex + 1].Type -eq 'GroupEnd')) {
    $currentPropertyIndex++
    $ValueToSet += $group[$CurrentPropertyIndex].Content
}

This checks the condition before looping, so encounters the ',' operator and ends the loop. It still supports the advanced variables such as $Test.Nested.Variable, which I think was the original intention of the Do Until loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant