Sanitize command names and descriptions (#17228)

This commit is contained in:
Emily Hedlund
2026-01-22 11:41:51 -05:00
committed by GitHub
parent 048c30513e
commit d956c5b221
6 changed files with 134 additions and 7 deletions
+21
View File
@@ -123,6 +123,27 @@ export function stripUnsafeCharacters(str: string): string {
.join('');
}
/**
* Sanitize a string for display in list-like UI components (e.g. Help, Suggestions).
* Removes ANSI codes, collapses whitespace characters into a single space, and optionally truncates.
*/
export function sanitizeForListDisplay(
str: string,
maxLength?: number,
): string {
if (!str) {
return '';
}
let sanitized = stripAnsi(str).replace(/\s+/g, ' ');
if (maxLength && sanitized.length > maxLength) {
sanitized = sanitized.substring(0, maxLength - 3) + '...';
}
return sanitized;
}
const stringWidthCache = new LRUCache<string, number>(
LRU_BUFFER_PERF_CACHE_LIMIT,
);