Skip to content

Commit

Permalink
Fix exporting and importing of invalid values
Browse files Browse the repository at this point in the history
  • Loading branch information
sofiia-chorna authored and Luthaf committed Jul 29, 2024
1 parent a0f7bf6 commit d8220a1
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,18 @@ export abstract class OptionsGroup {
assert(keys.length >= 1);
const value = option.value;

let root = settings as any;
for (const key of keys.slice(0, keys.length - 1)) {
if (!(key in root)) {
root[key] = {};
// Save property value if valid
if (value !== undefined || value !== null || !Number.isNaN(value)) {
let root = settings as any;
for (const key of keys.slice(0, keys.length - 1)) {
if (!(key in root)) {
root[key] = {};
}
root = root[key];
}
root = root[key];
const lastKey = keys[keys.length - 1];
root[lastKey] = value;
}
const lastKey = keys[keys.length - 1];
root[lastKey] = value;
});
/* eslint-enable */
return settings;
Expand Down Expand Up @@ -371,7 +374,15 @@ export abstract class OptionsGroup {
const lastKey = keys[keys.length - 1];

if (lastKey in root) {
option.value = root[lastKey];
const value = root[lastKey];

// send warning if the value is invalid and omit applying it
if (value === undefined || value === null || Number.isNaN(value)) {
sendWarning(`ignored setting '${lastKey}' with invalid value '${value}'`);
return;
}

option.value = value;

// remove used keys from the settings to be able to warn on
// unused keys
Expand Down

0 comments on commit d8220a1

Please sign in to comment.