Skip to content

Commit ba498fd

Browse files
committed
Ensure number options are coerced from string - fixes porsager#622
1 parent f0897e8 commit ba498fd

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/index.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ function parseOptions(a, b) {
393393
query.sslmode && (query.ssl = query.sslmode, delete query.sslmode)
394394
'timeout' in o && (console.log('The timeout option is deprecated, use idle_timeout instead'), o.idle_timeout = o.timeout) // eslint-disable-line
395395

396+
const ints = ['idle_timeout', 'connect_timeout', 'max_lifetime', 'max_pipeline', 'backoff', 'keep_alive']
396397
const defaults = {
397398
max : 10,
398399
ssl : false,
@@ -416,12 +417,16 @@ function parseOptions(a, b) {
416417
database : o.database || o.db || (url.pathname || '').slice(1) || env.PGDATABASE || user,
417418
user : user,
418419
pass : o.pass || o.password || url.password || env.PGPASSWORD || '',
419-
...Object.entries(defaults).reduce((acc, [k, d]) =>
420-
(acc[k] = k in o ? o[k] : k in query
420+
...Object.entries(defaults).reduce(
421+
(acc, [k, d]) => {
422+
const value = k in o ? o[k] : k in query
421423
? (query[k] === 'disable' || query[k] === 'false' ? false : query[k])
422-
: env['PG' + k.toUpperCase()] || d,
423-
acc
424-
),
424+
: env['PG' + k.toUpperCase()] || d
425+
acc[k] = typeof value === 'string' && ints.includes(k)
426+
? +value
427+
: value
428+
return acc
429+
},
425430
{}
426431
),
427432
connection : {

0 commit comments

Comments
 (0)