fix: handle invalid values in arrays (#61)
This commit is contained in:
parent
6f4ed9d662
commit
2dcc7efe6f
2 changed files with 28 additions and 4 deletions
|
|
@ -183,6 +183,10 @@ interface HasRequiredConfigMissingOptions {
|
||||||
userConfig?: DxtUserConfigValues;
|
userConfig?: DxtUserConfigValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isInvalidSingleValue(value: unknown): boolean {
|
||||||
|
return value === undefined || value === null || value === "";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if an extension has missing required configuration
|
* Check if an extension has missing required configuration
|
||||||
* @param manifest The extension manifest
|
* @param manifest The extension manifest
|
||||||
|
|
@ -203,10 +207,9 @@ export function hasRequiredConfigMissing({
|
||||||
if (configOption.required) {
|
if (configOption.required) {
|
||||||
const value = config[key];
|
const value = config[key];
|
||||||
if (
|
if (
|
||||||
value === undefined ||
|
isInvalidSingleValue(value) ||
|
||||||
value === null ||
|
(Array.isArray(value) &&
|
||||||
value === "" ||
|
(value.length === 0 || value.some(isInvalidSingleValue)))
|
||||||
(Array.isArray(value) && value.length === 0)
|
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -408,6 +408,27 @@ describe("hasRequiredConfigMissing", () => {
|
||||||
expect(result).toBe(true);
|
expect(result).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should return true when required config is array with invalid values", () => {
|
||||||
|
const manifest: DxtManifest = {
|
||||||
|
...baseManifest,
|
||||||
|
user_config: {
|
||||||
|
paths: {
|
||||||
|
type: "string",
|
||||||
|
title: "Paths",
|
||||||
|
description: "File paths",
|
||||||
|
required: true,
|
||||||
|
multiple: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = hasRequiredConfigMissing({
|
||||||
|
manifest,
|
||||||
|
userConfig: { paths: [""] },
|
||||||
|
});
|
||||||
|
expect(result).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
it("should return true when required config is empty array", () => {
|
it("should return true when required config is empty array", () => {
|
||||||
const manifest: DxtManifest = {
|
const manifest: DxtManifest = {
|
||||||
...baseManifest,
|
...baseManifest,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue