mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-09-09 22:31:05 +00:00
fix: normalize endpoints without regex backtracking
This commit is contained in:
parent
6dfe4cb535
commit
7e299624f8
2 changed files with 14 additions and 2 deletions
|
|
@ -91,7 +91,7 @@ export function resolveConfig(
|
|||
input.dreamCron || env.REME_DSH_DREAM_CRON || DEFAULT_CONFIG.dreamCron,
|
||||
};
|
||||
|
||||
config.endpoint = String(config.endpoint).replace(/\/+$/, "");
|
||||
config.endpoint = stripTrailingSlashes(String(config.endpoint));
|
||||
assertEndpoint(config.endpoint);
|
||||
config.requestTimeoutMs = integer(
|
||||
config.requestTimeoutMs,
|
||||
|
|
@ -173,6 +173,12 @@ function assertEndpoint(value: string): void {
|
|||
}
|
||||
}
|
||||
|
||||
function stripTrailingSlashes(value: string): string {
|
||||
let end = value.length;
|
||||
while (end > 0 && value.charCodeAt(end - 1) === 47) end -= 1;
|
||||
return value.slice(0, end);
|
||||
}
|
||||
|
||||
function integer(
|
||||
value: unknown,
|
||||
minimum: number,
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ export function resolveOpenClawConfig(
|
|||
stringValue(input.endpoint) ||
|
||||
env.REME_URL ||
|
||||
`http://${env.REME_HOST || "127.0.0.1"}:${env.REME_PORT || "2333"}`;
|
||||
const normalizedEndpoint = endpoint.replace(/\/+$/, "");
|
||||
const normalizedEndpoint = stripTrailingSlashes(endpoint);
|
||||
const url = new URL(normalizedEndpoint);
|
||||
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
||||
throw new TypeError("ReMe endpoint must be an absolute http(s) URL");
|
||||
|
|
@ -107,6 +107,12 @@ function integer(
|
|||
);
|
||||
}
|
||||
|
||||
function stripTrailingSlashes(value: string): string {
|
||||
let end = value.length;
|
||||
while (end > 0 && value.charCodeAt(end - 1) === 47) end -= 1;
|
||||
return value.slice(0, end);
|
||||
}
|
||||
|
||||
function finite(value: unknown, fallback: number): number {
|
||||
const number = Number(value);
|
||||
return Number.isFinite(number) ? number : fallback;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue