microsoft / winget-dsc

MIT License
23 stars 14 forks source link

[GitDsc/GitConfigUserName]: UserName isn't set properly if it contains whitespace #43

Closed mdanish-kh closed 5 months ago

mdanish-kh commented 5 months ago

Brief description of your issue

Set method does not work if the UserName resource parameter contains whitespace. The method isn't also idempotent with multiple runs. Looking at the code, it occurs at this line:

https://github.com/microsoft/winget-dsc/blob/ce47d703cb00a0e24f6de9d5c560df25c2f2d845/resources/GitDsc/GitDsc.psm1#L246

PowerShell will strip the quotation marks when passing the string param. A quick fix would be to quote the param properly before sending it to Invoke-GitConfig

Steps to reproduce

User a UserName value with whitespaces

$gitUserNameConfig = @{ UserName="Hello World"; ConfigLocation = "global" }
Invoke-DscResource -Name GitConfigUserName -Method Set -Property $gitUserNameConfig

Expected behavior

The global user.name value should be set properly.

Actual behavior

The command argument is passed as git config --global user.name Hello World when it should be passed as git config --global user.name 'Hello World'. This causes the name to be set improperly and by running the Set method multiple times it adds multiple name values in .gitconfig which breaks its idempotency.

gitconfig output with by running Set twice.

[user]
    email = <email>
    name = Hello
    name = Hello

Environment

Latest module code from the main branch