fix(node): JSON-escape plain-text input in read_json_bytes_as_arrow - #3080
fix(node): JSON-escape plain-text input in read_json_bytes_as_arrow#3080phil-opp wants to merge 1 commit into
Conversation
When the JSON schema inference fails, `read_json_bytes_as_arrow` retries by treating the input as a plain string. It did so by wrapping the raw bytes in `"` quotes (`wrapped_quoted`), which produces invalid JSON whenever the input itself contains a `"`, a backslash, or a raw control character (newline/tab). Both inference attempts then fail and the input is rejected with "failed to infer JSON schema" instead of becoming a string array. This is reachable from `dora run` interactive mode, whose Data prompt advertises "String/JSON": typing `say "hi"`, pasting a multi-line value, or entering a Windows path like `C:\Users\node` all failed. Fix by JSON-escaping the bytes (via `serde_json`) before wrapping, so any plain-text input is encoded as a valid JSON string literal. Adds regression tests for double quotes, backslashes, and control characters, plus a guard that bare JSON values still parse natively. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SD4dBVimzepwKSh2b9F8aG
|
⏳ Waiting to start tests on this pull request - details. |
Automated code-review pass — summaryThis is the tracking comment for a machine-generated code-review pass over the repository (branches suffixed off freshly-fetched PRs opened, by categoryCorrectness
Simplification / Optimization
Documentation
Rejected findings (with one-line reasons)
Validation
Generated by Claude Code |
|
🤖 Automated review by Claude — fully automated, no human in the loop. Findings are suggestions to verify. Reviewed the diff against the surrounding code. The fix is correct: The added tests are meaningful and would fail against the old
No issues found. (Minor, non-blocking: Generated by Claude Code |
Issue
read_json_bytes_as_arrow(apis/rust/node/src/daemon_connection/json_to_arrow.rs) first tries to parse the input as JSON, and on failure retries by treating it as a plain string. The retry (wrapped_quoted) wrapped the raw bytes in"quotes:If the input itself contains a
", a backslash, or a raw control character (newline/tab), the wrapped result is invalid JSON, so both the JSON attempt and the string-fallback attempt fail and the whole call errors withfailed to infer JSON schemainstead of yielding a string array.This is reachable from
dora runinteractive mode, whose Data prompt advertises "String/JSON …" (apis/rust/node/src/daemon_connection/interactive.rs:140). Concretely, these all failed before this change:say "hi"→ produced{ "inner":"say "hi""}(invalid JSON)C:\Users\nodeFix
JSON-escape the bytes via
serde_jsonbefore wrapping, so any plain-text input becomes a valid JSON string literal.wrapped_quotedis replaced by a smalljson_quotehelper. Behavior for bare JSON values (numbers, objects, arrays) is unchanged — they still parse natively on the first attempt.Validation
json_to_arrow.rscovering double quotes, backslashes, and control characters round-tripping to the expected string, plus a guard that a bare JSON number still parses as a non-string array.cargo test -p dora-node-api --lib json_to_arrow— 4 passed.cargo fmt --all -- --checkandcargo clippy -p dora-node-api -- -D warningsclean.🤖 This is a machine-generated pull request opened by Claude Code as part of an automated code-review pass. Please review carefully before merging.
🤖 Generated with Claude Code
Generated by Claude Code