commit c91e188d74a0e91051c822d6107e4653103cd162
parent 3dafaa168c235cb4595e7b253860d334ef087b95
Author: Florian Dold <dold@taler.net>
Date: Tue, 21 Jul 2026 20:04:13 +0200
util: correct assorted config accessor defects
load() tested its source name with "in", which walks the prototype chain;
getNumber returned rounded values past 2^53; getSectionNames upper-cased
keys that already were; orDefault was mistyped; one message had a typo.
Diffstat:
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/packages/taler-util/src/talerconfig.ts b/packages/taler-util/src/talerconfig.ts
@@ -178,7 +178,7 @@ export class ConfigValue<T> {
}
}
- orDefault(v: T): T | undefined {
+ orDefault(v: T): T {
if (this.value !== undefined) {
return this.converter(this.value);
} else {
@@ -734,10 +734,10 @@ export class Configuration {
}
/**
- * Get upper-cased section names.
+ * Get the section names, spelled as they were first written.
*/
getSectionNames(): string[] {
- return Object.keys(this.sectionMap).map((x) => x.toUpperCase());
+ return Object.values(this.sectionMap).map((sec) => sec.name);
}
getString(section: string, option: string): ConfigValue<string> {
@@ -785,6 +785,13 @@ export class Configuration {
`invalid config value for [${secNorm}]/${optNorm}, expected number`,
);
}
+ // The C parses with a range-checked strtoll. Returning a rounded value
+ // for anything past 2^53 would be worse than refusing it.
+ if (!Number.isSafeInteger(n)) {
+ throw Error(
+ `invalid config value for [${secNorm}]/${optNorm}, number out of range`,
+ );
+ }
return n;
};
return new ConfigValue(secNorm, optNorm, val, convert);
@@ -934,7 +941,7 @@ export class Configuration {
if (configSource == null) {
cs = defaultConfigSource;
} else if (typeof configSource === "string") {
- if (configSource in ConfigSources) {
+ if (Object.prototype.hasOwnProperty.call(ConfigSources, configSource)) {
cs = ConfigSources[configSource as keyof typeof ConfigSources];
} else {
throw Error("invalid config source");
@@ -1026,7 +1033,7 @@ export class Configuration {
const filename = this.hintEntrypoint;
if (!filename) {
throw Error(
- "unknown configuration entrypoing, unable to write back config file",
+ "unknown configuration entrypoint, unable to write back config file",
);
}
nodejs_fs.writeFileSync(