From 6cb541c8ded9a36c847117d22d7a1a0127b1e97a Mon Sep 17 00:00:00 2001 From: ksmithut Date: Wed, 2 Nov 2022 08:27:54 -0600 Subject: [PATCH 1/2] Fixes passing in family parameter in URL in node 18 Node 18 stopped coercing the type for its options (specifically the ip family option) and instead throws an error. So if you pass in `?family=6` in your Redis URL, it would fail because when it does the DNS lookup passing in the string `'6'`, node would throw an error. --- lib/utils/index.ts | 6 ++++++ test/unit/redis.ts | 3 +++ test/unit/utils.ts | 8 ++++++++ 3 files changed, 17 insertions(+) diff --git a/lib/utils/index.ts b/lib/utils/index.ts index 150f000d..c1d52aa0 100644 --- a/lib/utils/index.ts +++ b/lib/utils/index.ts @@ -236,6 +236,12 @@ export function parseURL(url: string): Record { if (parsed.port) { result.port = parsed.port; } + if (typeof options.family === 'string') { + const intFamily = Number.parseInt(options.family, 10); + if (!Number.isNaN(intFamily)) { + result.family = intFamily; + } + } defaults(result, options); return result; diff --git a/test/unit/redis.ts b/test/unit/redis.ts index f12d2dd9..5ede16bd 100644 --- a/test/unit/redis.ts +++ b/test/unit/redis.ts @@ -96,6 +96,9 @@ describe("Redis", () => { tls: { hostname: "example.test" }, }); expect(option.tls).to.deep.equal({ hostname: "example.test" }); + + option = getOption("redis://localhost?family=6"); + expect(option).to.have.property("family", 6); } catch (err) { stub.restore(); throw err; diff --git a/test/unit/utils.ts b/test/unit/utils.ts index f9386ac9..6f4c4bfe 100644 --- a/test/unit/utils.ts +++ b/test/unit/utils.ts @@ -195,6 +195,14 @@ describe("utils", () => { password: "pass", key: "value", }); + expect(utils.parseURL("redis://127.0.0.1/?family=6")).to.eql({ + host: "127.0.0.1", + family: 6 + }); + expect(utils.parseURL("redis://127.0.0.1/?family=IPv6")).to.eql({ + host: "127.0.0.1", + family: "IPv6" + }); }); }); From 5b8038e6d8902fbad2d7d353bafbd6c310086f2d Mon Sep 17 00:00:00 2001 From: ksmithut Date: Wed, 2 Nov 2022 08:31:45 -0600 Subject: [PATCH 2/2] fixes formatting --- lib/utils/index.ts | 2 +- test/unit/utils.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/utils/index.ts b/lib/utils/index.ts index c1d52aa0..9cd6da3e 100644 --- a/lib/utils/index.ts +++ b/lib/utils/index.ts @@ -236,7 +236,7 @@ export function parseURL(url: string): Record { if (parsed.port) { result.port = parsed.port; } - if (typeof options.family === 'string') { + if (typeof options.family === "string") { const intFamily = Number.parseInt(options.family, 10); if (!Number.isNaN(intFamily)) { result.family = intFamily; diff --git a/test/unit/utils.ts b/test/unit/utils.ts index 6f4c4bfe..7aa80822 100644 --- a/test/unit/utils.ts +++ b/test/unit/utils.ts @@ -197,11 +197,11 @@ describe("utils", () => { }); expect(utils.parseURL("redis://127.0.0.1/?family=6")).to.eql({ host: "127.0.0.1", - family: 6 + family: 6, }); expect(utils.parseURL("redis://127.0.0.1/?family=IPv6")).to.eql({ host: "127.0.0.1", - family: "IPv6" + family: "IPv6", }); }); });