Fix crash on unicode character (#16420)

This commit is contained in:
christine betts
2026-01-12 11:52:19 -05:00
committed by GitHub
parent 7b7f2fc69e
commit 64c75cb767
2 changed files with 27 additions and 2 deletions

View File

@@ -9,9 +9,26 @@ import type {
ToolCallConfirmationDetails,
ToolEditConfirmationDetails,
} from '@google/gemini-cli-core';
import { escapeAnsiCtrlCodes, stripUnsafeCharacters } from './textUtils.js';
import {
escapeAnsiCtrlCodes,
stripUnsafeCharacters,
getCachedStringWidth,
} from './textUtils.js';
describe('textUtils', () => {
describe('getCachedStringWidth', () => {
it('should handle unicode characters that crash string-width', () => {
// U+0602 caused string-width to crash (see #16418)
const char = '؂';
expect(getCachedStringWidth(char)).toBe(1);
});
it('should handle unicode characters that crash string-width with ANSI codes', () => {
const charWithAnsi = '\u001b[31m' + '؂' + '\u001b[0m';
expect(getCachedStringWidth(charWithAnsi)).toBe(1);
});
});
describe('stripUnsafeCharacters', () => {
it('should not strip tab characters', () => {
const input = 'hello world';