fix: use slice instead of splice to avoid modifying value of environment variable

This commit is contained in:
Viren070
2025-08-31 20:17:07 +01:00
parent bd88d3de8b
commit ee2ea419ba
2 changed files with 5 additions and 5 deletions
+2 -2
View File
@@ -35,7 +35,7 @@ export const baseOptions = (
name: string,
resources: Resource[],
timeout: number = Env.DEFAULT_TIMEOUT,
baseUrls?: string[]
baseUrls?: readonly string[]
): Option[] => {
const urlOption: Option = {
id: 'url',
@@ -55,7 +55,7 @@ export const baseOptions = (
label: baseUrls[0],
value: 'undefined',
},
...baseUrls.splice(1).map((url) => ({
...baseUrls.slice(1).map((url) => ({
label: url,
value: url,
})),
+3 -3
View File
@@ -92,7 +92,7 @@ const namedRegexes = makeValidator((x) => {
const removeTrailingSlash = (x: string) =>
x.endsWith('/') ? x.slice(0, -1) : x;
const presetUrls = makeExactValidator<string[]>((x) => {
const presetUrls = makeExactValidator<readonly string[]>((x) => {
if (typeof x !== 'string') {
throw new EnvError('Preset URLs must be a string or an array of strings');
}
@@ -111,10 +111,10 @@ const presetUrls = makeExactValidator<string[]>((x) => {
'Preset URLs must be an array of URLs or a single URL'
);
}
return urls.map(removeTrailingSlash);
return Object.freeze(urls.map(removeTrailingSlash));
} catch (e) {
if (typeof x === 'string' && validateUrl(x)) {
return [removeTrailingSlash(x)];
return Object.freeze([removeTrailingSlash(x)]);
}
throw new EnvError('Preset URLs must be an array of URLs or a single URL');
}