mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 08:03:39 +00:00
Fix crash on Unicode format characters in visibleWidth
Strip all Unicode format characters (category Cf) before passing to string-width. These are invisible control characters that crash string-width but have no visible width anyway. Closes #390
This commit is contained in:
parent
7f0cd8bcb5
commit
1d9fa13d58
1 changed files with 2 additions and 1 deletions
|
|
@ -5,7 +5,8 @@ import stringWidth from "string-width";
|
|||
*/
|
||||
export function visibleWidth(str: string): number {
|
||||
if (!str) return 0;
|
||||
const normalized = str.replace(/\t/g, " ");
|
||||
// Replace tabs and strip Unicode format characters (Cf) that crash string-width
|
||||
const normalized = str.replace(/\t/g, " ").replace(/\p{Cf}/gu, "");
|
||||
return stringWidth(normalized);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue