Bug Description
The Add-Arg helper function builds CLI arguments in the format key=value without quoting the value. When a value contains spaces, the CLI may parse it incorrectly.
Actual Behavior
The current code on line 150:
[array]$list += "$($key.Trim())=$value"
When called with a value containing spaces, e.g.:
Add-Arg $argsList "--description" "My Cool Service"
This produces:
--description=My Cool Service
Depending on how servy-cli.exe parses its arguments, My Cool Service may be split into separate tokens, resulting in only My being used as the description while Cool and Service are treated as unknown arguments.
Expected Behavior
Values should be quoted to preserve spaces:
--description="My Cool Service"
Suggested Fix
Wrap the value in double quotes inside the Add-Arg function:
[array]$list += "$($key.Trim())=`"$value`""
Or alternatively, only quote when the value contains spaces:
if ($value.Contains(" ")) {
[array]$list += "$($key.Trim())=`"$value`""
} else {
[array]$list += "$($key.Trim())=$value"
}
Affected Parameters
Any parameter that could contain spaces, including but not limited to:
--description
--path
--startupDir
--params
--stdout / --stderr
--displayName
- All pre-launch, post-launch, pre-stop, and post-stop path parameters
Environment
- PowerShell module:
Servy.psm1
- Affects:
Add-Arg function (line 150), impacts all functions that build CLI arguments
Bug Description
The
Add-Arghelper function builds CLI arguments in the formatkey=valuewithout quoting the value. When a value contains spaces, the CLI may parse it incorrectly.Actual Behavior
The current code on line 150:
When called with a value containing spaces, e.g.:
This produces:
Depending on how
servy-cli.exeparses its arguments,My Cool Servicemay be split into separate tokens, resulting in onlyMybeing used as the description whileCoolandServiceare treated as unknown arguments.Expected Behavior
Values should be quoted to preserve spaces:
Suggested Fix
Wrap the value in double quotes inside the
Add-Argfunction:Or alternatively, only quote when the value contains spaces:
Affected Parameters
Any parameter that could contain spaces, including but not limited to:
--description--path--startupDir--params--stdout/--stderr--displayNameEnvironment
Servy.psm1Add-Argfunction (line 150), impacts all functions that build CLI arguments