fix: handle invalid values in arrays (#61)

This commit is contained in:
Samuel Attard 2025-07-10 16:10:48 -07:00 • committed by GitHub
commit 2dcc7efe6f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 28 additions and 4 deletions

View file

@ -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;
}

View file

@ -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,