Skip to content

Commit

Permalink
fix: passing in family parameter in URL in node 18 (#1673)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksmithut authored Nov 2, 2022
1 parent 4de8cdb commit 6f1ab9f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ export function parseURL(url: string): Record<string, unknown> {
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;
Expand Down
3 changes: 3 additions & 0 deletions test/unit/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions test/unit/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
});
});
});

Expand Down

0 comments on commit 6f1ab9f

Please sign in to comment.