fix: escape all control characters in diagnostics JSON output#397
Conversation
The `esc()` function in `crates/logfwd-io/src/diagnostics.rs` previously only escaped `"`, `\`, `\n`, `\r`, and `\t`. Other ASCII control characters (0x00-0x1F) were passed through unescaped, causing the `/api/pipelines` endpoint to produce invalid JSON when configuration strings (like pipeline names or SQL) contained such characters. This change: - Updates `esc()` to escape all control characters (0x00-0x1F). - Maintains existing named escapes (`\n`, `\r`, `\t`) for backward compatibility and readability. - Uses the `\uXXXX` format for all other control characters. - Adds a unit test `test_esc_control_chars` and an integration test `test_pipelines_endpoint_escaping` to verify correct behavior. Tested with `cargo test -p logfwd-io`. Co-authored-by: strawgate <6384545+strawgate@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughThe Possibly related PRs
🚥 Pre-merge checks | ✅ 1 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@crates/logfwd-io/src/diagnostics.rs`:
- Around line 657-660: The match arm that handles control characters uses
write!(out, "\\u{:04x}", c as u32).unwrap(); — replace the bare .unwrap() with
.expect(...) to document why this is safe (e.g., .expect("writing to String is
infallible") ) so the call remains explicit and complies with the guideline;
locate the write! invocation in the control-character branch in diagnostics.rs
and change only the unwrap to an expect message.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: bef6649a-9703-40ed-b712-fa9beb242006
📒 Files selected for processing (1)
crates/logfwd-io/src/diagnostics.rs
The `esc()` function in `crates/logfwd-io/src/diagnostics.rs` previously only escaped `"`, `\`, `\n`, `\r`, and `\t`. Other ASCII control characters (0x00-0x1F) were passed through unescaped, causing the `/api/pipelines` endpoint to produce invalid JSON when configuration strings (like pipeline names or SQL) contained such characters. This change: - Updates `esc()` to escape all control characters (0x00-0x1F). - Maintains existing named escapes (`\n`, `\r`, `\t`) for backward compatibility and readability. - Uses the `\uXXXX` format for all other control characters. - Adds a unit test `test_esc_control_chars` and an integration test `test_pipelines_endpoint_escaping` to verify correct behavior. - Fixes formatting issues in the new tests. Tested with `cargo test -p logfwd-io`. Co-authored-by: strawgate <6384545+strawgate@users.noreply.github.com>
…Copilot <223556219+Copilot@users.noreply.github.com>
|
Addressed the open review feedback with a surgical code change.
Validation
Also attempted full Note 🔒 Integrity filtering filtered 1 itemIntegrity filtering activated and filtered the following item during workflow execution.
What is this? | From workflow: AI: Address PR Review Feedback Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@crates/logfwd-io/src/diagnostics.rs`:
- Around line 1004-1010: The test test_esc_control_chars should be expanded to
iterate over the full control byte range 0x00..=0x1F and assert esc produces the
exact expected escape for each value; modify the test to loop bytes b in
0u8..=0x1F, convert to a single-byte string and call esc, then compute the
expected output (use the known named escapes for 0x09->"\t", 0x0A->"\n",
0x0D->"\r" and for all other control bytes expect the unicode escape form
"\\u00XX" with uppercase hex) and assert_eq!(esc(...), expected). Keep the test
name test_esc_control_chars and update assertions to cover every control byte so
regressions for unlisted bytes are caught.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 8159ea18-c750-4ca5-93f6-0302ec0e6a9f
📒 Files selected for processing (1)
crates/logfwd-io/src/diagnostics.rs
|
Addressed the remaining unresolved review feedback in
Validation run
Note 🔒 Integrity filtering filtered 1 itemIntegrity filtering activated and filtered the following item during workflow execution.
What is this? | From workflow: AI: Address PR Review Feedback Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@crates/logfwd-io/src/diagnostics.rs`:
- Around line 1008-1015: The loop currently calls format! and .to_string() each
iteration; instead allocate a reusable String before the loop and build expected
into it with push/push_str and write! for the fallback: declare let mut expected
= String::with_capacity(8) outside the loop, inside the loop do
expected.clear(); expected.push('x'); match ch { '\t' =>
expected.push_str("\\t"), '\n' => expected.push_str("\\n"), '\r' =>
expected.push_str("\\r"), _ => write!(&mut expected, "\\u{:04x}", b).unwrap() };
expected.push('y'); and use that expected (and remove the per-iteration
format!/to_string() calls referring to input, expected_mid, expected, ch and b).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 1cba2c9a-f2a4-49f5-a6d2-4e9fff79f1f8
📒 Files selected for processing (1)
crates/logfwd-io/src/diagnostics.rs
ef06f4a to
0e06b35
Compare
Fixed an issue in the diagnostics JSON escaping where ASCII control characters (0x00-0x1F) were not being escaped, leading to invalid JSON output. Added unit and integration tests to ensure all control characters are properly handled using either named escapes or the
\uXXXXformat.Fixes #381
PR created automatically by Jules for task 13652391228897795876 started by @strawgate