diff --git a/lib/dns.js b/lib/dns.js index ae0e14bab3097d..ca932ad05f4da7 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -28,7 +28,6 @@ const { } = primordials; const cares = internalBinding('cares_wrap'); -const { toASCII } = require('internal/idna'); const { isIP } = require('internal/net'); const { customPromisifyArgs } = require('internal/util'); const errors = require('internal/errors'); @@ -220,7 +219,7 @@ function lookup(hostname, options, callback) { req.oncomplete = all ? onlookupall : onlookup; const err = cares.getaddrinfo( - req, toASCII(hostname), family, hints, verbatim, + req, hostname, family, hints, verbatim, ); if (err) { process.nextTick(callback, dnsException(err, 'getaddrinfo', hostname)); diff --git a/lib/internal/dns/callback_resolver.js b/lib/internal/dns/callback_resolver.js index 48e8f7df856c26..e57a597c08c716 100644 --- a/lib/internal/dns/callback_resolver.js +++ b/lib/internal/dns/callback_resolver.js @@ -7,8 +7,6 @@ const { Symbol, } = primordials; -const { toASCII } = require('internal/idna'); - const { codes: { ERR_INVALID_ARG_TYPE, @@ -70,7 +68,7 @@ function resolver(bindingName) { req.hostname = name; req.oncomplete = onresolve; req.ttl = !!(options && options.ttl); - const err = this._handle[bindingName](req, toASCII(name)); + const err = this._handle[bindingName](req, name); if (err) throw dnsException(err, bindingName, name); if (hasObserver('dns')) { startPerf(req, kPerfHooksDnsLookupResolveContext, { diff --git a/lib/internal/dns/promises.js b/lib/internal/dns/promises.js index df41d1267ef421..79be8591bbcad2 100644 --- a/lib/internal/dns/promises.js +++ b/lib/internal/dns/promises.js @@ -46,7 +46,6 @@ const { CANCELLED, } = dnsErrorCodes; const { codes, dnsException } = require('internal/errors'); -const { toASCII } = require('internal/idna'); const { isIP } = require('internal/net'); const { getaddrinfo, @@ -138,7 +137,7 @@ function createLookupPromise(family, hostname, all, hints, verbatim) { req.resolve = resolve; req.reject = reject; - const err = getaddrinfo(req, toASCII(hostname), family, hints, verbatim); + const err = getaddrinfo(req, hostname, family, hints, verbatim); if (err) { reject(dnsException(err, 'getaddrinfo', hostname)); @@ -274,7 +273,7 @@ function createResolverPromise(resolver, bindingName, hostname, ttl) { req.reject = reject; req.ttl = ttl; - const err = resolver._handle[bindingName](req, toASCII(hostname)); + const err = resolver._handle[bindingName](req, hostname); if (err) reject(dnsException(err, bindingName, hostname)); diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index aab07945786cec..da546b15f264c2 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -20,6 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. #include "cares_wrap.h" +#include "ada.h" #include "async_wrap-inl.h" #include "base64-inl.h" #include "base_object-inl.h" @@ -1558,6 +1559,7 @@ void GetAddrInfo(const FunctionCallbackInfo& args) { CHECK(args[4]->IsBoolean()); Local req_wrap_obj = args[0].As(); node::Utf8Value hostname(env->isolate(), args[1]); + std::string ascii_hostname = ada::idna::to_ascii(hostname.ToStringView()); int32_t flags = 0; if (args[3]->IsInt32()) { @@ -1590,17 +1592,18 @@ void GetAddrInfo(const FunctionCallbackInfo& args) { hints.ai_socktype = SOCK_STREAM; hints.ai_flags = flags; - TRACE_EVENT_NESTABLE_ASYNC_BEGIN2( - TRACING_CATEGORY_NODE2(dns, native), "lookup", req_wrap.get(), - "hostname", TRACE_STR_COPY(*hostname), - "family", - family == AF_INET ? "ipv4" : family == AF_INET6 ? "ipv6" : "unspec"); - - int err = req_wrap->Dispatch(uv_getaddrinfo, - AfterGetAddrInfo, - *hostname, - nullptr, - &hints); + TRACE_EVENT_NESTABLE_ASYNC_BEGIN2(TRACING_CATEGORY_NODE2(dns, native), + "lookup", + req_wrap.get(), + "hostname", + TRACE_STR_COPY(ascii_hostname.data()), + "family", + family == AF_INET ? "ipv4" + : family == AF_INET6 ? "ipv6" + : "unspec"); + + int err = req_wrap->Dispatch( + uv_getaddrinfo, AfterGetAddrInfo, ascii_hostname.data(), nullptr, &hints); if (err == 0) // Release ownership of the pointer allowing the ownership to be transferred USE(req_wrap.release());