Skip to content

Conversation

h16rkim
Copy link
Contributor

@h16rkim h16rkim commented Sep 27, 2025

Issue #, if available: #3117

Error Screenshot

image

Description of changes:

This issue does not occur in the currently released version(1.16.2). However, it can be reproduced on the current main branch. This error is occuring in the current released version (1.17.1)

When executing the /prompts list command, there is a function that trims the description if it is too long. However, if the trim happens at the boundary of a multibyte character, a panic occurs and the program terminates.

This PR fixes an issue that may occur in multibyte language systems such as Korean, Japanese, Chinese, Vietnamese, Thai, Arabic, emojis, etc..


After Applying this PR (Screenshot)

image

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

- Replace byte-based string slicing with character-based truncation
- Prevents panic when truncating multibyte characters (Korean, etc.)
- Add comprehensive test coverage for UTF-8 boundary cases
- Fix existing test compilation errors by adding missing fields
@h16rkim h16rkim changed the title fix: handle UTF-8 character boundaries in truncate_description fix: fix panic error while truncating MCP prompt description Sep 27, 2025
@h16rkim h16rkim changed the title fix: fix panic error while truncating MCP prompt description fix: fix error while truncating MCP prompt description Sep 27, 2025
@h16rkim h16rkim changed the title fix: fix error while truncating MCP prompt description fix: fix error when truncating MCP prompt description written in multibyte language Sep 27, 2025
@h16rkim h16rkim changed the title fix: fix error when truncating MCP prompt description written in multibyte language fix(prompts): fix error when truncating prompt description written in multibyte language Sep 27, 2025
@h16rkim h16rkim force-pushed the fix/prompt-description-truncate branch from 80f77f5 to f6e0ab2 Compare September 29, 2025 00:48
@h16rkim h16rkim changed the title fix(prompts): fix error when truncating prompt description written in multibyte language fix(prompts): fix error when truncating prompt description written in multibyte characters Sep 29, 2025
…n-truncate

# Conflicts:
#	crates/chat-cli/src/cli/chat/cli/prompts.rs
@h16rkim h16rkim changed the title fix(prompts): fix error when truncating prompt description written in multibyte characters fix:bug(prompts): fix error when truncating prompt description written in multibyte characters Oct 3, 2025
/// Truncates text to a maximum display width.
/// Takes into account the display width of characters, where CJK characters are counted as 2 units
/// wide. Returns the truncated text without ellipsis.
pub fn truncate_safe_with_width(text: &str, max_width: usize) -> String {
Copy link
Contributor Author

@h16rkim h16rkim Oct 6, 2025

Choose a reason for hiding this comment

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

In languages such as CJK, the width of a single character is twice of an alphabet letter. The code has been improved to correctly calculate the width even when the description is written in a CJK language.

image

@h16rkim h16rkim force-pushed the fix/prompt-description-truncate branch from 3c1ee5a to fe3fc2c Compare October 6, 2025 19:13
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.

2 participants