Skip to content

fix: preserve spaces in arguments during encryption/decryption#20

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

fix: preserve spaces in arguments during encryption/decryption#20
12end wants to merge 1 commit into
masterfrom
openhands/fix-args-with-spaces

Conversation

@12end

@12end 12end commented Jun 28, 2026

Copy link
Copy Markdown
Owner

Description

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

Problem

The original code used strings.Join(args, " ") and strings.Split(output, " ") to serialize/deserialize arguments. When an argument value contained spaces, it would be incorrectly split during decryption, losing the original argument count and content.

For example:

  • Input: --name "hello world"
  • Expected after decryption: ["--name", "hello world"]
  • Actual (buggy): ["--name", "hello", "world"]

Solution

Each argument is now base64-encoded individually before being joined with a newline separator. This ensures:

  1. Spaces within arguments are preserved (base64 doesn't use spaces)
  2. Empty arguments are preserved (base64 of empty string is non-empty)
  3. The original argument count and content are fully restored

Changes

  • cargs.go: Modified encryption to base64-encode each argument individually, joined by newline
  • cargs.go: Modified decryption to split by newline and base64-decode each argument
  • cargs_test.go: Added comprehensive tests for various edge cases
  • go.mod/go.sum: Added for dependency management

Testing

All tests pass:

  • Simple args without spaces
  • Args with single space
  • Args with multiple consecutive spaces
  • Args with leading and trailing spaces
  • Empty string arguments
  • Special characters
  • Realistic command line scenarios

Fixes #19

@12end can click here to continue refining the PR

- Base64 encode each argument individually before joining
- Use newline as separator instead of space (newline won't appear in base64)
- This fixes the issue where arguments with spaces were incorrectly split

Fixes #19
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