mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-23 07:01:40 +00:00
refactor: dedupe daemon lowercase helpers
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
||||
type ExecHostResponse,
|
||||
} from "../infra/exec-host.js";
|
||||
import { sanitizeHostExecEnv } from "../infra/host-env-security.js";
|
||||
import { normalizeLowercaseStringOrEmpty } from "../shared/string-coerce.js";
|
||||
import { buildSystemRunApprovalPlan, handleSystemRunInvoke } from "./invoke-system-run.js";
|
||||
import type {
|
||||
ExecEventPayload,
|
||||
@@ -43,9 +44,10 @@ const WINDOWS_CODEPAGE_ENCODING_MAP: Record<number, string> = {
|
||||
};
|
||||
let cachedWindowsConsoleEncoding: string | null | undefined;
|
||||
|
||||
const execHostEnforced = process.env.OPENCLAW_NODE_EXEC_HOST?.trim().toLowerCase() === "app";
|
||||
const execHostEnforced =
|
||||
normalizeLowercaseStringOrEmpty(process.env.OPENCLAW_NODE_EXEC_HOST ?? "") === "app";
|
||||
const execHostFallbackAllowed =
|
||||
process.env.OPENCLAW_NODE_EXEC_FALLBACK?.trim().toLowerCase() !== "0";
|
||||
normalizeLowercaseStringOrEmpty(process.env.OPENCLAW_NODE_EXEC_FALLBACK ?? "") !== "0";
|
||||
const preferMacAppExecHost = process.platform === "darwin" && execHostEnforced;
|
||||
|
||||
type SystemWhichParams = {
|
||||
@@ -84,7 +86,7 @@ function isCmdExeInvocation(argv: string[]): boolean {
|
||||
if (!token) {
|
||||
return false;
|
||||
}
|
||||
const base = path.win32.basename(token).toLowerCase();
|
||||
const base = normalizeLowercaseStringOrEmpty(path.win32.basename(token));
|
||||
return base === "cmd.exe" || base === "cmd";
|
||||
}
|
||||
|
||||
@@ -152,7 +154,7 @@ export function decodeCapturedOutputBuffer(params: {
|
||||
return utf8;
|
||||
}
|
||||
const encoding = params.windowsEncoding ?? resolveWindowsConsoleEncoding();
|
||||
if (!encoding || encoding.toLowerCase() === "utf-8") {
|
||||
if (!encoding || normalizeLowercaseStringOrEmpty(encoding) === "utf-8") {
|
||||
return utf8;
|
||||
}
|
||||
try {
|
||||
@@ -298,7 +300,7 @@ function resolveExecutable(bin: string, env?: Record<string, string>) {
|
||||
process.platform === "win32"
|
||||
? (process.env.PATHEXT ?? process.env.PathExt ?? ".EXE;.CMD;.BAT;.COM")
|
||||
.split(";")
|
||||
.map((ext) => ext.toLowerCase())
|
||||
.map((ext) => normalizeLowercaseStringOrEmpty(ext))
|
||||
: [""];
|
||||
for (const dir of resolveEnvPath(env)) {
|
||||
for (const ext of extensions) {
|
||||
@@ -433,7 +435,9 @@ export async function handleInvoke(
|
||||
await sendJsonPayloadResult(client, frame, payload);
|
||||
} catch (err) {
|
||||
const message = String(err);
|
||||
const code = message.toLowerCase().includes("timed out") ? "TIMEOUT" : "INVALID_REQUEST";
|
||||
const code = normalizeLowercaseStringOrEmpty(message).includes("timed out")
|
||||
? "TIMEOUT"
|
||||
: "INVALID_REQUEST";
|
||||
await sendErrorResult(client, frame, code, message);
|
||||
}
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user