Skip to content

fix(parser): preserve CRLF byte offsets during JSON extraction - #3991

Merged
pszymkowiak merged 3 commits into
rtk-ai:developfrom
tianhaotian:fix/parser-crlf-json-offset
Nov 22, 2026
Merged

pszymkowiak merged 3 commits into
rtk-ai:developfrom
tianhaotian:fix/parser-crlf-json-offset

Conversation

@tianhaotian

Copy link
Copy Markdown
Contributor

Summary

  • Fix extract_json_object fallback offsets on CRLF and mixed line endings by retaining the actual line terminators; skip indentation so the returned slice begins at {.
  • Cover the reported multibyte-prefix panic, exact JSON extraction across line endings/Unicode/indentation/marker variants, and incomplete objects.

Fixes #3903. The marker-path regression coverage in #2533 is separate from this fallback-path fix.

Test plan

  • cargo fmt --all --check
  • cargo clippy --all-targets
  • cargo test --all — 3572 passed, 8 ignored.
  • cargo test --all -- --ignored --test-threads=1 — all 8 additional tests passed.
  • Red/green check: the new CRLF/Unicode regression panics before the production fix; all 18 parser tests pass afterward.
  • Manual rtk vitest check with a failing shim emitting CRLF and an accented path: original diagnostics remain visible and exit status remains 1, with no panic.
  • Focused hyperfine comparison of the actual before/after extraction functions (20,000 calls with a 100-line LF prefix, 15 runs): 54.7 ms before / 21.2 ms after. This measures parser throughput, not whole-command startup.

Validated on macOS arm64 with Rust 1.98.0. The full suite required normal filesystem access for existing initialization tests that write RTK's application-support directory.

@CLAassistant

CLAassistant commented Sep 12, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@rtk-wshm-sync-bot rtk-wshm-sync-bot Bot added bug Something isn't working rust parser labels Sep 12, 2026
@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

Fixes a byte-offset calculation bug in extract_json_object's fallback path where CRLF and mixed line endings caused incorrect offsets, leading to panics on multibyte-prefixed input. Adds extensive regression tests covering line endings, Unicode, indentation, marker variants, and incomplete JSON objects.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #3903


Analyzed automatically by wshm · This is an automated analysis, not a human review.

@pszymkowiak pszymkowiak left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @tianhaotian. Reproduced end to end on native Windows with a stub vitest printing CRLF output with an accented line right before a JSON object: develop panics (start byte index 47 is not a char boundary; it is inside 'é', exit 101, output lost), this branch passes the output through and keeps vitest's exit code. Parser and vitest tests pass on Linux and Windows, and CI is green after the branch update.

@pszymkowiak
pszymkowiak merged commit 762708c into rtk-ai:develop Nov 22, 2026
16 checks passed
@rtk-release-bot rtk-release-bot Bot mentioned this pull request Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working parser rust

Projects

None yet

Development

Successfully merging this pull request may close these issues.

panic 'not a char boundary' in extract_json_object fallback path on CRLF input (same class as #2509)

3 participants