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',