Skip to content

fix(parser): use char_indices to prevent panic on CJK/emoji output - #2749

Closed
guyoron1 wants to merge 2 commits into
rtk-ai:developfrom
guyoron1:fix/cjk-char-boundary-panic
Closed

guyoron1 wants to merge 2 commits into
rtk-ai:developfrom
guyoron1:fix/cjk-char-boundary-panic

Conversation

@guyoron1

@guyoron1 guyoron1 commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • extract_json_object() panics with 'not a char boundary' when JSON output contains multi-byte UTF-8 characters (CJK, emoji)
  • Root cause: char indices from enumerate() were used as byte offsets when slicing the input string — char index != byte offset for multi-byte characters
  • Fix: replace Vec<char> + enumerate() with char_indices() which yields proper byte offsets directly

Fixes #2509

Test plan

  • Added regression tests for Korean, Japanese, and emoji in JSON objects
  • Added test for CJK prefix text before JSON (non-ASCII start_pos)
  • Added test for nested JSON with CJK values
  • cargo test --all passes (CI)

extract_json_object() used char indices as byte offsets when slicing
the input string. Multi-byte UTF-8 characters (CJK, emoji) caused
'not a char boundary' panics because char index != byte offset.

Replace Vec<char> + enumerate() with char_indices() which yields
proper byte offsets directly.

Fixes rtk-ai#2509
@guyoron1

Copy link
Copy Markdown
Contributor Author

Superseded by #2751 which was merged with the same char_indices fix.

@guyoron1 guyoron1 closed this Jul 24, 2026
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.

Panic 'not a char boundary' in output filter (src/parser/mod.rs:191) on large CJK output — affects all wrapped commands (same root as #1837)

1 participant