openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
18 lines (17 loc) • 786 B
JavaScript
//#region src/gateway/chat-input-sanitize.ts
const DISALLOWED_CHAT_CONTROL_RANGE = `${String.fromCharCode(0)}-${String.fromCharCode(8)}${String.fromCharCode(11)}${String.fromCharCode(12)}${String.fromCharCode(14)}-${String.fromCharCode(31)}${String.fromCharCode(127)}`;
const DISALLOWED_CHAT_CONTROL_RE = new RegExp(`[${DISALLOWED_CHAT_CONTROL_RANGE}]`, "g");
/** Normalize chat text and reject null bytes before routing to channels. */
function sanitizeChatSendMessageInput(message) {
const normalized = message.normalize("NFC");
if (normalized.includes("\0")) return {
ok: false,
error: "message must not contain null bytes"
};
return {
ok: true,
message: normalized.replace(DISALLOWED_CHAT_CONTROL_RE, "")
};
}
//#endregion
export { sanitizeChatSendMessageInput as t };