mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-18 15:03:02 +00:00
Fix crash when bash mode outputs binary data
Sanitize shell output by removing Unicode Format characters and lone surrogates that crash string-width. This fixes crashes when running commands like curl that download binary files.
This commit is contained in:
parent
a054fecd11
commit
ad42ebf5f5
5 changed files with 141 additions and 111 deletions
|
|
@ -87,6 +87,21 @@ export function getShellConfig(): { shell: string; args: string[] } {
|
|||
return cachedShellConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize binary output for display/storage.
|
||||
* Removes characters that crash string-width or cause display issues:
|
||||
* - Control characters (except tab, newline, carriage return)
|
||||
* - Lone surrogates
|
||||
* - Unicode Format characters (crash string-width due to a bug)
|
||||
*/
|
||||
export function sanitizeBinaryOutput(str: string): string {
|
||||
// Fast path: use regex to remove problematic characters
|
||||
// - \p{Format}: Unicode format chars like \u0601 that crash string-width
|
||||
// - \p{Surrogate}: Lone surrogates from invalid UTF-8
|
||||
// - Control chars except \t \n \r
|
||||
return str.replace(/[\p{Format}\p{Surrogate}]/gu, "").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g, "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Kill a process and all its children (cross-platform)
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue