From caa558f7eb00ca3ca608e0c7f2acd42a5018b464 Mon Sep 17 00:00:00 2001 From: Josh Deeden Date: Wed, 5 Aug 2026 11:46:56 -0700 Subject: [PATCH] Fix the unreachable unknown-database-type guard (#1091) '!name in config' parses as '(!name) in config', which tests whether the boolean false is a key of the config object. It never is, so the throw was dead code for every input. An unrecognised --db value instead failed two lines later with "TypeError: config[name] is not a function", pointing at the wrong line. Use Object.hasOwn rather than the minimal '!(name in config)': plain 'in' walks the prototype chain, so --db=toString would have passed the guard and handed config.toString(parts), the string "[object Object]", on as the connection settings. Unknown types now report "unknown database type ''" as intended. sqlite, mysql, sqlite: and the no-argument default are unchanged. --- app/config.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/config.js b/app/config.js index 9ccad6da..5e4e820d 100644 --- a/app/config.js +++ b/app/config.js @@ -205,7 +205,10 @@ function getDatabaseConfig(dbType, isTesting) { mysql: !isTesting ? getMysqlDefault : getMysqlTesting, sqlite: getSqliteConfig, } - if (!name in config) { + // note: hasOwn, not 'in': '!name in config' parses as '(!name) in config' + // which is always false; and plain 'in' would accept inherited keys + // like "toString" as database names. + if (!Object.hasOwn(config, name)) { throw new Error(`unknown database type '${dbType}'`) } return {