mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-21 10:16:44 +00:00
fix(scripts): reject flag device-pair Telegram values
This commit is contained in:
@@ -43,6 +43,10 @@ type DevicePairTelegramArgs = {
|
||||
const BOOLEAN_FLAGS = new Set(["--help", "-h"]);
|
||||
const VALUE_FLAGS = new Set(["--account", "-a", "--chat", "-c"]);
|
||||
|
||||
function isMissingOptionValue(value: string | undefined): boolean {
|
||||
return !value || BOOLEAN_FLAGS.has(value) || VALUE_FLAGS.has(value) || value.startsWith("--");
|
||||
}
|
||||
|
||||
function writeStdoutLine(...parts: string[]): void {
|
||||
process.stdout.write(`${parts.join(" ")}\n`);
|
||||
}
|
||||
@@ -84,7 +88,7 @@ function validateArgs(args: readonly string[]): void {
|
||||
}
|
||||
if (VALUE_FLAGS.has(arg)) {
|
||||
const value = args[index + 1];
|
||||
if (!value || value.startsWith("--")) {
|
||||
if (isMissingOptionValue(value)) {
|
||||
throw new CliArgumentError(`${arg} requires a value`);
|
||||
}
|
||||
index += 1;
|
||||
|
||||
@@ -21,6 +21,24 @@ describe("scripts/dev/test-device-pair-telegram.ts", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects option tokens as device-pair Telegram values", () => {
|
||||
for (const flag of ["--chat", "-c", "--account", "-a"]) {
|
||||
expect(() => parseDevicePairTelegramArgs([flag, "-h"])).toThrow(
|
||||
`${flag} requires a value`,
|
||||
);
|
||||
}
|
||||
expect(() => parseDevicePairTelegramArgs(["--chat", "--help"])).toThrow(
|
||||
"--chat requires a value",
|
||||
);
|
||||
});
|
||||
|
||||
it("allows negative Telegram chat ids", () => {
|
||||
expect(parseDevicePairTelegramArgs(["--chat", "-100123"])).toMatchObject({
|
||||
chatId: "-100123",
|
||||
help: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects unknown args before loading OpenClaw plugins", async () => {
|
||||
const cfg = { channels: { telegram: { enabled: true } } };
|
||||
const loadOpenClawPlugins = vi.fn();
|
||||
|
||||
Reference in New Issue
Block a user