node:dns: treat null lookup option fields as unset

Merged
RO
3mo ago
+48-15

Fixes #37318

Repro

const dns = require("node:dns");
dns.lookup("127.0.0.1", { hints: null }, (e, a, f) => console.log(e, a, f));

Node prints null 127.0.0.1 4. Bun threw synchronously:

TypeError: The "undefined" argument must be of type number. Received null
  code: "ERR_INVALID_ARG_TYPE"

{ all: null } and { verbatim: null } threw the same way. Node treats a null option field the same as an absent one (its guards are != null).

Cause

In src/js/node/dns.ts, validateFlagsOption, validateAllOption and validateVerbatimOption only skipped undefined, so null fell through to validateNumber/validateBoolean. (family and order already handled null.)

Additionally, the native getaddrinfo options parser (src/runtime/dns_jsc/options_jsc.rs) rejected a null flags value while already treating null family, socktype, protocol and backend as unset, so a null hints forwarded by node:dns would have failed there next.

Fix

  • dns.ts: the three guards now skip null as well, matching Node's != null checks. Non-null invalid values (hints: "a", all: 1, verbatim: 0) still throw ERR_INVALID_ARG_TYPE.
  • options_jsc.rs: a null flags is treated as unset, consistent with the other fields.

This overlaps with one bullet of #33516, which is a broader lookup() validation rework that has gone stale and now conflicts with main; this PR is just the null handling the issue reports.

Verification

New tests in test/js/node/dns/node-dns.test.js cover {hints|all|verbatim|order|family: null} for both dns.lookup and dns.promises.lookup (6 of 10 fail on the released binary), and test/js/bun/dns/resolve-dns.test.ts covers Bun.dns.lookup with flags: null (fails on the released binary). All pass with this change, and both files report the same pre-existing pass/fail counts as main otherwise (the failures are network-bound tests that cannot resolve external domains in this sandbox).


no test proof · iteration 0 · Platform-specific test(s) that do not run on this machine. Deferring to CI, which covers all platforms: test/js/bun/dns/resolve-dns.test.ts test/js/node/dns/node-dns.test.js