Skip to content

Fix: preserve arguments with spaces during encryption/decryption#18

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

Fix: preserve arguments with spaces during encryption/decryption#18
12end wants to merge 1 commit into
masterfrom
openhands/fix-arg-encoding-with-spaces-v2

Conversation

@12end

@12end 12end commented Jun 28, 2026

Copy link
Copy Markdown
Owner

Summary

This PR fixes issue #16: Arguments containing spaces were incorrectly split during the encryption/decryption cycle.

Problem

The original implementation used strings.Join(args, " ") and strings.Split(output, " ") to serialize/deserialize arguments. When arguments contained spaces (e.g., --name "hello world"), they were incorrectly split into multiple argument after decryption.

Solution

Instead of joining arguments with a space separator, each argument is now individually base64-encoded, then joined with a NULL separator (\x00). This ensures:

  1. Arguments with spaces are preserved correctly
  2. Arguments with tabs, newlines, or other special characters work properly
  3. Empty arguments are handled correctly
  4. The NULL separator never appears in base64 output, so there are no conflicts

Changes

  • Modified cargs.go: Added encodeArgs() and decodeArgs() helper functions
  • Added cargs_test.go: Test cases covering various edge cases including spaces, empty strings, special characters, unicode, etc.

Testing

All tests pass:

  • Simple arguments
  • Arguments with single/multiple spaces
  • Multiple arguments with spaces
  • Empty arguments
  • Arguments with special characters, newlines, tabs, unicode

This PR was created by an AI agent (OpenHands) on behalf of the user.

The original implementation used strings.Join(args, " ") and strings.Split(output, " ")
to serialize/deserialize arguments. This caused issues when arguments contained spaces,
as they were incorrectly split into multiple arguments.

The fix encodes each argument individually using base64, then joins them with a NULL
separator (\x00). Base64 output only contains alphanumeric characters plus '+', '/',
and '=', which cannot appear in the separator. This ensures arguments with spaces,
tabs, newlines, or other special characters are preserved correctly.

Also handle empty strings by encoding them as a single space before base64 encoding.

Fixes #16

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.

2 participants