Skip to content

Fix: preserve spaces in argument values through encrypt/decrypt cycle#21

Draft
12end wants to merge 1 commit into
masterfrom
openhands/fix-args-with-spaces-v3
Draft

Fix: preserve spaces in argument values through encrypt/decrypt cycle#21
12end wants to merge 1 commit into
masterfrom
openhands/fix-args-with-spaces-v3

Conversation

@12end

@12end 12end commented Jun 28, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes #19: Arguments containing spaces were incorrectly split after the encrypt/decrypt cycle in cargs.Init.

Problem

cargs.Init used strings.Join(args, " ") and strings.Split(output, " ") to serialize/deserialize arguments. Since space was used as both a delimiter and a valid character in argument values, arguments like --name "hello world" would become ["--name", "hello", "world"] after decryption instead of ["--name", "hello world"].

Solution

Each argument is now individually base64-encoded before being joined with a newline character (\n) — which is never produced by base64 encoding. On decryption, arguments are split by newline and individually base64-decoded. This preserves the exact argument boundaries and content through the round-trip.

Changes

  • cargs.go: Replaced strings.Join/strings.Split with per-argument base64 encoding using newline as delimiter
  • cargs_test.go: Added tests verifying arguments with spaces and consecutive spaces survive the round-trip
  • testdata/helper/main.go: Test helper binary used for integration testing of the full encrypt/decrypt cycle

Verification

$ go test -tags cargs -v -run TestArgs ./...
=== RUN   TestArgsWithSpaces
--- PASS: TestArgsWithSpaces (0.20s)
=== RUN   TestArgsWithConsecutiveSpaces
--- PASS: TestArgsWithConsecutiveSpaces (0.18s)
PASS

This PR was created by an AI agent (OpenHands) on behalf of @12end.

@12end can click here to continue refining the PR

Previously, cargs.Init used strings.Join/Split with space as delimiter,
which broke arguments containing spaces (e.g. '--name "hello world"'
would become '--name', 'hello', 'world' after encrypt/decrypt).

Now each argument is individually base64-encoded, then joined with
newline - a character never produced by base64 encoding. On decrypt,
arguments are split by newline and individually decoded.

Fixes #19

Co-authored-by: openhands <openhands@all-hands.dev>
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.

Bug:包含空格的参数值在加解密后会被错误拆分,导致参数个数/内容丢失

2 participants