From 6f1ab9f374bff2d62cf64ff6bfca1cf9f03d14d5 Mon Sep 17 00:00:00 2001 From: Keith Smith Date: Wed, 2 Nov 2022 08:35:07 -0600 Subject: [PATCH] fix: passing in family parameter in URL in node 18 (#1673) --- 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..9cd6da3e 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..7aa80822 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", + }); }); });