mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 10:41:25 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -15,10 +15,18 @@ function cleanCandidate(raw: string) {
|
||||
}
|
||||
|
||||
function isValidMedia(candidate: string, opts?: { allowSpaces?: boolean }) {
|
||||
if (!candidate) return false;
|
||||
if (candidate.length > 4096) return false;
|
||||
if (!opts?.allowSpaces && /\s/.test(candidate)) return false;
|
||||
if (/^https?:\/\//i.test(candidate)) return true;
|
||||
if (!candidate) {
|
||||
return false;
|
||||
}
|
||||
if (candidate.length > 4096) {
|
||||
return false;
|
||||
}
|
||||
if (!opts?.allowSpaces && /\s/.test(candidate)) {
|
||||
return false;
|
||||
}
|
||||
if (/^https?:\/\//i.test(candidate)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Local paths: only allow safe relative paths starting with ./ that do not traverse upwards.
|
||||
return candidate.startsWith("./") && !candidate.includes("..");
|
||||
@@ -26,11 +34,17 @@ function isValidMedia(candidate: string, opts?: { allowSpaces?: boolean }) {
|
||||
|
||||
function unwrapQuoted(value: string): string | undefined {
|
||||
const trimmed = value.trim();
|
||||
if (trimmed.length < 2) return undefined;
|
||||
if (trimmed.length < 2) {
|
||||
return undefined;
|
||||
}
|
||||
const first = trimmed[0];
|
||||
const last = trimmed[trimmed.length - 1];
|
||||
if (first !== last) return undefined;
|
||||
if (first !== `"` && first !== "'" && first !== "`") return undefined;
|
||||
if (first !== last) {
|
||||
return undefined;
|
||||
}
|
||||
if (first !== `"` && first !== "'" && first !== "`") {
|
||||
return undefined;
|
||||
}
|
||||
return trimmed.slice(1, -1).trim();
|
||||
}
|
||||
|
||||
@@ -48,7 +62,9 @@ export function splitMediaFromOutput(raw: string): {
|
||||
// KNOWN: Leading whitespace is semantically meaningful in Markdown (lists, indented fences).
|
||||
// We only trim the end; token cleanup below handles removing `MEDIA:` lines.
|
||||
const trimmedRaw = raw.trimEnd();
|
||||
if (!trimmedRaw.trim()) return { text: "" };
|
||||
if (!trimmedRaw.trim()) {
|
||||
return { text: "" };
|
||||
}
|
||||
|
||||
const media: string[] = [];
|
||||
let foundMediaToken = false;
|
||||
@@ -189,7 +205,9 @@ export function splitMediaFromOutput(raw: string): {
|
||||
// Return cleaned text if we found a media token OR audio tag, otherwise original
|
||||
text: foundMediaToken || hasAudioAsVoice ? cleanedText : trimmedRaw,
|
||||
};
|
||||
if (hasAudioAsVoice) result.audioAsVoice = true;
|
||||
if (hasAudioAsVoice) {
|
||||
result.audioAsVoice = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user