From 61315d3cea5ae9ae195312545da977107a22aded Mon Sep 17 00:00:00 2001 From: Dan Hensby Date: Thu, 19 Nov 2026 14:43:57 +0000 Subject: [PATCH] fix: parse the connection string ApplicationIntent value without case The parser set readOnlyIntent only for the all-lowercase value "readonly". ApplicationIntent=ReadOnly, the casing in the Microsoft docs, gave a read-write connection. Compare the trimmed value without case. An empty value now gives the same config as a left-out key, so the driver default applies. Co-Authored-By: Claude Opus 5.5 --- lib/base/connection-pool.js | 13 +++++++++---- test/common/unit.js | 38 +++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/lib/base/connection-pool.js b/lib/base/connection-pool.js index e11be7f6..b96c5b7a 100644 --- a/lib/base/connection-pool.js +++ b/lib/base/connection-pool.js @@ -151,11 +151,16 @@ class ConnectionPool extends EventEmitter { switch (key) { case 'application name': break - case 'applicationintent': - Object.assign(config.options, { - readOnlyIntent: value === 'readonly' - }) + case 'applicationintent': { + // the value is not case-sensitive; an empty value is not set + const intent = value.trim().toLowerCase() + if (intent) { + Object.assign(config.options, { + readOnlyIntent: intent === 'readonly' + }) + } break + } case 'asynchronous processing': break case 'attachdbfilename': diff --git a/test/common/unit.js b/test/common/unit.js index a1d4a95d..c79935e8 100644 --- a/test/common/unit.js +++ b/test/common/unit.js @@ -869,8 +869,46 @@ describe('connection string encrypt option', () => { }) }) +describe('connection string application intent option', () => { + it('does not set readOnlyIntent when ApplicationIntent is left out', () => { + const config = BasePool._parseConnectionString('Server=localhost') + assert.strictEqual('readOnlyIntent' in config.options, false) + }) + + it('does not set readOnlyIntent when ApplicationIntent is empty', () => { + const config = BasePool._parseConnectionString('Server=localhost;ApplicationIntent=;Database=db') + assert.strictEqual('readOnlyIntent' in config.options, false) + assert.strictEqual(config.database, 'db') + }) + + it('does not set readOnlyIntent when ApplicationIntent is only whitespace', () => { + const config = BasePool._parseConnectionString('Server=localhost;ApplicationIntent={ }') + assert.strictEqual('readOnlyIntent' in config.options, false) + }) + + for (const value of ['ReadOnly', 'readonly', 'READONLY', ' ReadOnly ', '{ ReadOnly }']) { + it(`parses ApplicationIntent=${value} as read-only intent`, () => { + const config = BasePool._parseConnectionString(`Server=localhost;ApplicationIntent=${value}`) + assert.strictEqual(config.options.readOnlyIntent, true) + }) + } + + for (const value of ['ReadWrite', 'readwrite']) { + it(`parses ApplicationIntent=${value} as read-write intent`, () => { + const config = BasePool._parseConnectionString(`Server=localhost;ApplicationIntent=${value}`) + assert.strictEqual(config.options.readOnlyIntent, false) + }) + } + + it('uses ApplicationIntent=ReadOnly in the tedious config', () => { + const config = new ConnectionPool('Server=localhost;ApplicationIntent=ReadOnly')._config() + assert.strictEqual(config.options.readOnlyIntent, true) + }) +}) + describe('connection string empty values', () => { const keys = [ + 'ApplicationIntent', 'Connection Timeout', 'ConnectRetryInterval', 'Encrypt',