Skip to content

Comments

fix: parser mishandles escapes in quoted arguments#18

Open
TopangaLudwitt wants to merge 1 commit intoopenclaw:mainfrom
TopangaLudwitt:fix/parser-quoted-escapes
Open

fix: parser mishandles escapes in quoted arguments#18
TopangaLudwitt wants to merge 1 commit intoopenclaw:mainfrom
TopangaLudwitt:fix/parser-quoted-escapes

Conversation

@TopangaLudwitt
Copy link

Summary

Fix tokenizeCommand escape handling in single-quoted and double-quoted strings.

Problem

Two failure modes reported in #17:

  1. Single-quoted strings: '{"prompt":"don'\'t"}' — escaped apostrophes caused Unclosed quote errors because escape processing was active inside single quotes
  2. Double-quoted strings: "{\"prompt\":\"line1\\nline2\"}" — backslash was stripped during escape processing, corrupting JSON escape sequences

Fix

  • Single-quoted strings: Skip escape processing entirely (all chars are literal, matching POSIX shell semantics)
  • Double-quoted strings: Preserve both the backslash and the next character (current += ch + next) instead of stripping the backslash

Tests

Added 3 new tests to test/parser.test.ts:

  • Single-quoted strings are fully literal
  • Double-quoted strings preserve escape sequences
  • --args-json with escaped JSON in double quotes

All 50 existing tests continue to pass (the 1 pre-existing failure in two approve gates can be resumed sequentially is unrelated).

Fixes #17

Single-quoted strings now treat all characters as literal (no escape
processing), matching POSIX shell semantics. Double-quoted strings
now preserve backslash escape sequences (both backslash and next char
are kept) instead of stripping the backslash.

This fixes two failure modes:
1. Escaped apostrophes in single-quoted JSON caused 'Unclosed quote' errors
2. JSON escape sequences in double-quoted --args-json payloads were corrupted
   (backslashes stripped, altering payload semantics)

Added 3 new parser tests for escape handling in both quote types.

Fixes openclaw#17
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.

Parser mishandles escaped characters in quoted args, breaking --args-json payloads

1 participant