mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-10 08:41:13 +00:00
21 lines
559 B
TypeScript
21 lines
559 B
TypeScript
import { stripAnsi } from "./ansi.js";
|
|
|
|
/**
|
|
* Normalize untrusted text for single-line terminal/log rendering.
|
|
*/
|
|
export function sanitizeTerminalText(input: string): string {
|
|
const normalized = stripAnsi(input)
|
|
.replace(/\r/g, "\\r")
|
|
.replace(/\n/g, "\\n")
|
|
.replace(/\t/g, "\\t");
|
|
let sanitized = "";
|
|
for (const char of normalized) {
|
|
const code = char.charCodeAt(0);
|
|
const isControl = (code >= 0x00 && code <= 0x1f) || (code >= 0x7f && code <= 0x9f);
|
|
if (!isControl) {
|
|
sanitized += char;
|
|
}
|
|
}
|
|
return sanitized;
|
|
}
|