From d1f8d8d62c3bd034af39ade6eeee7066dc56fca5 Mon Sep 17 00:00:00 2001 From: Dan Hensby Date: Wed, 18 Nov 2026 22:10:07 +0000 Subject: [PATCH] fix: treat an empty Encrypt value in a connection string as not set A connection string with an empty Encrypt value, for example `Server=h;Encrypt=;Database=d`, set `options.encrypt` to false. A connection string without Encrypt leaves `options.encrypt` unset, so tedious uses its default and encrypts. An empty value now gives the same result as a left-out key. @tediousjs/connection-string 1.1.2 gives the schema default for an empty boolean value. The encrypt override in NODE_MSSQL_SCHEMA has no default, so an empty value gives undefined, and the parser sets `options.encrypt` only when the value is a boolean. Explicit values do not change. Co-Authored-By: Claude Opus 5.5 --- lib/base/connection-pool.js | 9 ++++--- package-lock.json | 15 ++++++----- package.json | 2 +- test/common/unit.js | 54 +++++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 11 deletions(-) diff --git a/lib/base/connection-pool.js b/lib/base/connection-pool.js index 26f6ca61..57657ac4 100644 --- a/lib/base/connection-pool.js +++ b/lib/base/connection-pool.js @@ -12,6 +12,7 @@ const { CHANNELS, tracePromise, traceCallback, publish } = require('../diagnosti const NODE_MSSQL_SCHEMA = { ...MSSQL_SCHEMA, + encrypt: { type: 'boolean' }, useutc: { type: 'boolean' }, stream: { type: 'boolean' }, parsejson: { type: 'boolean' }, @@ -233,9 +234,11 @@ class ConnectionPool extends EventEmitter { break } case 'encrypt': - Object.assign(config.options, { - encrypt: !!value - }) + if (typeof value === 'boolean') { + Object.assign(config.options, { + encrypt: value + }) + } break case 'enlist': break diff --git a/package-lock.json b/package-lock.json index b821dd02..dae5dab5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "9.1.1", "license": "MIT", "dependencies": { - "@tediousjs/connection-string": "^1.0.0", + "@tediousjs/connection-string": "^1.1.2", "commander": "^11.0.0", "debug": "^4.3.3", "tarn": "^3.0.2", @@ -1358,9 +1358,10 @@ } }, "node_modules/@tediousjs/connection-string": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@tediousjs/connection-string/-/connection-string-1.1.0.tgz", - "integrity": "sha512-z9ZBWEG+8pIB5V1zYzlRPXx0oRJ5H7coPnMQK8EZOw03UTPI9Umn6viL36f5w+CuqkKsnCM50RVStpjZmR0Bng==" + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@tediousjs/connection-string/-/connection-string-1.1.2.tgz", + "integrity": "sha512-5/cyQUgWyCLYePCYY/esmDqeglU57S3sdTOqcYI4xA9cejMGjqICfEAUgALjDJ/JFN5RRXA4SYjFZ0q24b2HYA==", + "license": "MIT" }, "node_modules/@types/json5": { "version": "0.0.29", @@ -11865,9 +11866,9 @@ "dev": true }, "@tediousjs/connection-string": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@tediousjs/connection-string/-/connection-string-1.1.0.tgz", - "integrity": "sha512-z9ZBWEG+8pIB5V1zYzlRPXx0oRJ5H7coPnMQK8EZOw03UTPI9Umn6viL36f5w+CuqkKsnCM50RVStpjZmR0Bng==" + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@tediousjs/connection-string/-/connection-string-1.1.2.tgz", + "integrity": "sha512-5/cyQUgWyCLYePCYY/esmDqeglU57S3sdTOqcYI4xA9cejMGjqICfEAUgALjDJ/JFN5RRXA4SYjFZ0q24b2HYA==" }, "@types/json5": { "version": "0.0.29", diff --git a/package.json b/package.json index 5df02ee5..52fc362b 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ }, "license": "MIT", "dependencies": { - "@tediousjs/connection-string": "^1.0.0", + "@tediousjs/connection-string": "^1.1.2", "commander": "^11.0.0", "debug": "^4.3.3", "tarn": "^3.0.2", diff --git a/test/common/unit.js b/test/common/unit.js index 6cde3209..3de94fd8 100644 --- a/test/common/unit.js +++ b/test/common/unit.js @@ -815,6 +815,60 @@ describe('connection string boolean options', () => { }) }) +describe('connection string encrypt option', () => { + it('does not set encrypt when Encrypt is left out', () => { + const config = BasePool._parseConnectionString('Server=localhost') + assert.strictEqual('encrypt' in config.options, false) + }) + + it('does not set encrypt when Encrypt is empty', () => { + const config = BasePool._parseConnectionString('Server=localhost;Encrypt=') + assert.strictEqual('encrypt' in config.options, false) + }) + + it('does not set encrypt when Encrypt is empty and parses the next pair', () => { + const config = BasePool._parseConnectionString('Server=localhost;Encrypt=;Database=db') + assert.strictEqual('encrypt' in config.options, false) + assert.strictEqual(config.database, 'db') + }) + + it('does not set encrypt when Encrypt is only whitespace', () => { + const config = BasePool._parseConnectionString('Server=localhost;Encrypt={ }') + assert.strictEqual('encrypt' in config.options, false) + }) + + it('parses Encrypt=true as true', () => { + const config = BasePool._parseConnectionString('Server=localhost;Encrypt=true') + assert.strictEqual(config.options.encrypt, true) + }) + + it('parses Encrypt=yes as true', () => { + const config = BasePool._parseConnectionString('Server=localhost;Encrypt=yes') + assert.strictEqual(config.options.encrypt, true) + }) + + it('parses Encrypt=false as false', () => { + const config = BasePool._parseConnectionString('Server=localhost;Encrypt=false') + assert.strictEqual(config.options.encrypt, false) + }) + + it('parses Encrypt=no as false', () => { + const config = BasePool._parseConnectionString('Server=localhost;Encrypt=no') + assert.strictEqual(config.options.encrypt, false) + }) + + it('uses the tedious default when Encrypt is empty', () => { + const config = new ConnectionPool('Server=localhost;Encrypt=;Database=db')._config() + assert.strictEqual(config.options.encrypt, true) + assert.strictEqual(config.options.database, 'db') + }) + + it('uses Encrypt=false in the tedious config', () => { + const config = new ConnectionPool('Server=localhost;Encrypt=false')._config() + assert.strictEqual(config.options.encrypt, false) + }) +}) + describe('connection string auth - base', () => { it('parses basic login', () => { const config = BasePool._parseConnectionString('Server=database.test.com;Database=test;User Id=test;Password=admin')