From 09f3e55db2a28cfe7803379b82d08cf671cdd6ce Mon Sep 17 00:00:00 2001 From: Angel J Piscola Date: Mon, 6 Jul 2020 18:56:14 -0400 Subject: [PATCH] fix: properly override database url properties (#6247) * fix: properly override database url properties Closes #4878 * test: add test for overriding url options --- src/driver/DriverUtils.ts | 2 +- test/github-issues/4878/issue-4878.ts | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/github-issues/4878/issue-4878.ts diff --git a/src/driver/DriverUtils.ts b/src/driver/DriverUtils.ts index b410b84a3f9..b7e00b6c2ae 100644 --- a/src/driver/DriverUtils.ts +++ b/src/driver/DriverUtils.ts @@ -28,7 +28,7 @@ export class DriverUtils { if (buildOptions && buildOptions.useSid) { urlDriverOptions.sid = parsedUrl.database; } - return Object.assign({}, options, urlDriverOptions); + return Object.assign({}, urlDriverOptions, options); } return Object.assign({}, options); } diff --git a/test/github-issues/4878/issue-4878.ts b/test/github-issues/4878/issue-4878.ts new file mode 100644 index 00000000000..8359d8b0eda --- /dev/null +++ b/test/github-issues/4878/issue-4878.ts @@ -0,0 +1,19 @@ +import { DriverUtils } from "../../../src/driver/DriverUtils"; +import { expect } from "chai"; + +describe("github issues > #4878 URL Connection string not overridden by supplied options", () => { + it("should override url-built options with user-supplied options", () => { + const obj: any = { + username: "user", + password: "password", + host: "host", + database: "database", + port: 8888 + }; + + const url = `postgres://url_user:${obj.password}@${obj.host}:${obj.port}/${obj.database}`; + obj.url = url; + const options = DriverUtils.buildDriverOptions(obj); + expect(options.username).to.eql(obj.username); + }); +});