Commit b2230cf
committed
fix(chat): prevent panic on UTF-8 boundary when rendering response
When the AI response contains multi-byte characters (e.g. non-ASCII
text adjacent to triple backticks), the byte offset accumulated via
parsed.offset_from() can land in the middle of a UTF-8 character
boundary. The subsequent &buf[offset..] slice then panics at runtime.
The same pattern existed in two places:
- crates/chat-cli/src/cli/chat/mod.rs (streaming response loop)
- crates/chat-cli/src/cli/chat/parse.rs (validate! test macro loop)
Replace the direct slice with .get(offset..) which returns None
instead of panicking, and break the loop gracefully.
Add a regression test with Indonesian, Chinese, and emoji inputs
adjacent to triple backticks to verify no panic occurs.
Fixes #37151 parent e14ea18 commit b2230cf
2 files changed
Lines changed: 45 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3099 | 3099 | | |
3100 | 3100 | | |
3101 | 3101 | | |
3102 | | - | |
| 3102 | + | |
| 3103 | + | |
| 3104 | + | |
| 3105 | + | |
| 3106 | + | |
3103 | 3107 | | |
3104 | 3108 | | |
3105 | 3109 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
672 | 672 | | |
673 | 673 | | |
674 | 674 | | |
675 | | - | |
| 675 | + | |
| 676 | + | |
676 | 677 | | |
677 | 678 | | |
678 | 679 | | |
| |||
824 | 825 | | |
825 | 826 | | |
826 | 827 | | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
827 | 866 | | |
0 commit comments