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

Fix issue with escaped double quotes in CIM array #39

Conversation

FabienTschanz
Copy link
Contributor

This PR aims to address microsoft/Microsoft365DSC#5396 with nested quotes inside of a CIM array. Let's take the following input:

        IntuneMobileAppConfigurationPolicyIOS "IntuneMobileAppConfigurationPolicyIOS-Managed Devices - iOS"
        {
            # Shortened version, only relevant property left
            settings              = @("
                MSFT_appConfigurationSettingItem{
                    appConfigKeyType = 'stringType'
                    appConfigKeyValue = '[`"edge://flags`", `"edge://inspect`", `"edge://optimization-guide-internals`"]'
                    appConfigKey = 'URLBlocklist'
                }
            ");
        }

The issue here is that inside of the settings array with the CIM instance, there is another property named appConfigKeyValue. This is a string property that contains a sequence of characters and escaped double quotes. Those quotes were escaped from the Get-DSCBlock function, unnecessarily though. That aside, when converting that input using Convert-DSCStringParamToVariable to the final DSC string, it removes all double quotes. But here, we don't want that to happen, since they are an integral part of the appConfigKeyValue property.

The PR handles this issue by skipping escaped double quotes inside of the CIM array element and at the end, replacing the escaped version with one that does not have the escape character in it, so that the final output is equal to what was the input to Get-DSCBlock.

@FabienTschanz FabienTschanz changed the title Draft: Fix issue with escaped double quotes in CIM array Fix issue with escaped double quotes in CIM array Nov 20, 2024
@FabienTschanz
Copy link
Contributor Author

@NikCharlebois Ready for review. Got confirmation over in microsoft/Microsoft365DSC#5396 that it now works.

@FabienTschanz
Copy link
Contributor Author

@NikCharlebois Can you please take a look at this PR?

@ykuijs
Copy link
Member

ykuijs commented Dec 17, 2024

I have fixed a different issue yesterday, which is now in ReverseDSC but which looks very similar. Could you please check the issue with the most recent version of ReverseDSC?

FYI: I am working on another issue that was discovered yesterday. Will create a PR for that later, so any required additional changes I can include with this PR.

@FabienTschanz
Copy link
Contributor Author

@ykuijs Unfortunately it's not fixed with your change. I just checked with the IntuneAppConfigurationDevicePolicy. The correct output should be:

Settings              = @(
    MSFT_MicrosoftGraphappConfigurationSettingItem{
        AppConfigKey = "URLBlocklist"
        AppConfigKeyType = "stringType"
        AppConfigKeyValue = "[`"edge://flags`", `"edge://inspect`", `"edge://optimization-guide-internals`"]"
    }
    MSFT_MicrosoftGraphappConfigurationSettingItem{
        AppConfigKey = "ManagedFavorites"
        AppConfigKeyType = "stringType"
        AppConfigKeyValue = "[{ `"toplevel_name`": `"My managed favorites folder`" }, { `"name`": `"Google`", `"url`": `"google.com`" }, { `"name`": `"Yahoo`", `"url`": `"yahoo.com`" }]"
    }
);

but instead, it is:

Settings              = @(
    MSFT_MicrosoftGraphappConfigurationSettingItem{
        AppConfigKey = "URLBlocklist"
        AppConfigKeyType = "stringType"
        AppConfigKeyValue = "["edge://flags`, `edge://inspect`, `edge://optimization-guide-internals`]`
    }
    MSFT_MicrosoftGraphappConfigurationSettingItem{
        AppConfigKey = "ManagedFavorites"
        AppConfigKeyType = "stringType"
        AppConfigKeyValue = "[{ "toplevel_name`: `My managed favorites folder` }, { `name`: `Google`, `url`: `google.com` }, { `name`: `Yahoo`, `url`: `yahoo.com` }]`
    }
);

In the incorrect export, backticks are set and the double quotes are removed, even at the end of the property (see AppConfigKeyValue). Do you want me to take a look at it? I also need to rebase my changes on yours, since I'm not sure if we both touched the same stuff.

@ykuijs
Copy link
Member

ykuijs commented Dec 18, 2024

We probably did. I just added a description of what my changes tried to accomplish here: #41 (comment)

@ricmestre
Copy link
Contributor

ricmestre commented Dec 18, 2024

@ykuijs I've not being paying attention to these PRs since I'm currently testing AAD resources, but please remember that like I already explained before I rely on the way that the blueprints are exported, if you change something that was single quotes before and now it's double quotes or some similar change it will affect my product.

@ykuijs
Copy link
Member

ykuijs commented Dec 18, 2024

@ykuijs I've not being paying attention to these PRs since I'm currently testing AAD resources, but please remember that like I already explained before I rely on the way that the blueprints are exported, if you change something that was single quotes before and now it's double quotes or some similar change it will affect my product.

@ricmestre Oh yes, that is right. I totally forgot. My apologies for that!

@FabienTschanz FabienTschanz force-pushed the fix/escaped-quotes-in-cim-array branch from 161aa24 to 934f438 Compare December 18, 2024 15:24
@FabienTschanz
Copy link
Contributor Author

FabienTschanz commented Dec 18, 2024

@ykuijs I updated the PR to include your changes and re-engineered the way it works. With this version, it now correctly escapes double quotes inside of a string property in a CIM instance. Example previously:

Settings              = @(
    MSFT_MicrosoftGraphappConfigurationSettingItem{
        AppConfigKey = "URLBlocklist"
        AppConfigKeyType = "stringType"
        AppConfigKeyValue = "["edge://flags`, `edge://inspect`, `edge://optimization-guide-internals`]`
    }
    MSFT_MicrosoftGraphappConfigurationSettingItem{
        AppConfigKey = "ManagedFavorites"
        AppConfigKeyType = "stringType"
        AppConfigKeyValue = "[{ "toplevel_name`: `My managed favorites folder` }, { `name`: `Google`, `url`: `google.com` }, { `name`: `Yahoo`, `url`: `yahoo.com` }]`
    }
);

And now:

Settings              = @(
    MSFT_MicrosoftGraphappConfigurationSettingItem{
        AppConfigKeyType = "stringType"
        AppConfigKey = "URLBlocklist"
        AppConfigKeyValue = "[`"edge://flags`", `"edge://inspect`", `"edge://optimization-guide-internals`"]"
    }
    MSFT_MicrosoftGraphappConfigurationSettingItem{
        AppConfigKeyType = "stringType"
        AppConfigKey = "ManagedFavorites"
        AppConfigKeyValue = "[{ `"toplevel_name`": `"My managed favorites folder`" }, { `"name`": `"Google`", `"url`": `"google.com`" }, { `"name`": `"Yahoo`", `"url`": `"yahoo.com`" }]"
    }
);

The second version compiles perfectly fine and has the correct visual representation.

@FabienTschanz FabienTschanz deleted the fix/escaped-quotes-in-cim-array branch February 14, 2025 06:36
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

Successfully merging this pull request may close these issues.

3 participants