fix(ui): address pr review comments regarding ansi reset vulnerability

This commit is contained in:
Spencer
2026-03-25 19:04:15 +00:00
parent 760dbc3e06
commit e1bff8590c
2 changed files with 17 additions and 10 deletions
+2 -7
View File
@@ -171,7 +171,7 @@ export const TableRenderer: React.FC<TableRendererProps> = ({
}
// --- Pre-wrap and Optimize Widths ---
const actualColumnWidths = new Array(numColumns).fill(0);
const actualColumnWidths: number[] = new Array<number>(numColumns).fill(0);
const wrapAndProcessRow = (row: StyleSpan[][]) => {
const rowResult: ProcessedLine[][] = [];
@@ -202,11 +202,7 @@ export const TableRenderer: React.FC<TableRendererProps> = ({
const wrappedRows = styledRows.map((row) => wrapAndProcessRow(row));
// Use the TIGHTEST widths that fit the wrapped content + padding
const adjustedWidths = actualColumnWidths.map(
(w) =>
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
w + COLUMN_PADDING,
);
const adjustedWidths = actualColumnWidths.map((w) => w + COLUMN_PADDING);
return { wrappedHeaders, wrappedRows, adjustedWidths };
}, [styledHeaders, styledRows, terminalWidth]);
@@ -257,7 +253,6 @@ export const TableRenderer: React.FC<TableRendererProps> = ({
isHeader = false,
): React.ReactNode => {
const renderedCells = cells.map((cell, index) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const width = adjustedWidths[index] || 0;
return renderCell(cell, width, isHeader);
});
+15 -3
View File
@@ -40,7 +40,11 @@ export const parseToStyleSpans = (text: string): StyleSpan[] => {
if (
ansiCode === '\x1b[0m' ||
ansiCode === '\x1b[39m' ||
ansiCode === '\x1b[49m'
ansiCode === '\x1b[49m' ||
ansiCode === '\x1b[22m' ||
ansiCode === '\x1b[23m' ||
ansiCode === '\x1b[24m' ||
ansiCode === '\x1b[29m'
) {
if (ansiCode === '\x1b[0m') {
currentAnsiState = [];
@@ -54,8 +58,16 @@ export const parseToStyleSpans = (text: string): StyleSpan[] => {
// eslint-disable-next-line no-control-regex
(c) => !c.match(/\x1b\[4\d(?:;\d+)*m/),
);
} else {
currentAnsiState.push(ansiCode);
} else if (ansiCode === '\x1b[22m') {
currentAnsiState = currentAnsiState.filter(
(c) => c !== '\x1b[1m' && c !== '\x1b[2m',
);
} else if (ansiCode === '\x1b[23m') {
currentAnsiState = currentAnsiState.filter((c) => c !== '\x1b[3m');
} else if (ansiCode === '\x1b[24m') {
currentAnsiState = currentAnsiState.filter((c) => c !== '\x1b[4m');
} else if (ansiCode === '\x1b[29m') {
currentAnsiState = currentAnsiState.filter((c) => c !== '\x1b[9m');
}
} else {
currentAnsiState.push(ansiCode);