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;
|
||||
}
|
||||
|
||||
function isInvalidSingleValue(value: unknown): boolean {
|
||||
return value === undefined || value === null || value === "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an extension has missing required configuration
|
||||
* @param manifest The extension manifest
|
||||
|
|
@ -203,10 +207,9 @@ export function hasRequiredConfigMissing({
|
|||
if (configOption.required) {
|
||||
const value = config[key];
|
||||
if (
|
||||
value === undefined ||
|
||||
value === null ||
|
||||
value === "" ||
|
||||
(Array.isArray(value) && value.length === 0)
|
||||
isInvalidSingleValue(value) ||
|
||||
(Array.isArray(value) &&
|
||||
(value.length === 0 || value.some(isInvalidSingleValue)))
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -408,6 +408,27 @@ describe("hasRequiredConfigMissing", () => {
|
|||
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", () => {
|
||||
const manifest: DxtManifest = {
|
||||
...baseManifest,
|
||||
|
|
|
|||
Loading…
Reference in a new issue