cli icon indicating copy to clipboard operation
cli copied to clipboard

JSON output containing file paths invalid

Open nskerl opened this issue 7 months ago • 0 comments

The bug

When using --output-format json with package zip create command, the json returned contains single backslash characters which are not legal according to json.org spec.

Command to reproduce

Use the octopus cli to create a package specifying json as the output format:

octopus package zip create --id 'test.package' --version '0.0.1' --base-path 'c:\temp\packageme' --out-folder 'c:\temp\' --include '**' --overwrite --no-prompt --output-format json | Out-String

Outcome

The above command returns the file path of the package in json

{"Path":"c:\temp\test.package.0.0.1.zip"}

Note the single backslash characters (notably the \t which are control characters). I would expect the output to be escaped, as:

{"Path":"c:\\temp\\test.package.0.0.1.zip"}

When parsing the unescaped output via powershell, the file path is corrupted as the \t in the above path is interpreted as tab characters:

> '{"Path":"c:\temp\test.package.0.0.1.zip"}' | ConvertFrom-Json

Path
----
c:      emp     est.package.0.0.1.zip

To workaround the issue you can do the escaping yourself:

$result = $output -replace '\\', '\\\\' | ConvertFrom-Json

Versions

cli: 2.16.0

Octopus Server: n/a

Links

nskerl avatar May 12 '25 22:05 nskerl