Skip to content

Add-Arg does not quote values containing spaces #54

@Christophe-Rogiers

Description

@Christophe-Rogiers

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions