# HG changeset patch # User Kim Alvefur # Date 1574565831 -3600 # Node ID 0d702ec77f0c56fdd2b2a806a02f71fe571935d3 # Parent 7777f25d5266ef882cdb0806290cbbd3ae487748 net.resolvers.basic: Move IP literal check to constructor This is to prepare for fixing #1459. An IPv6 literal in [ ] brackets does not pass IDNA and resolving it fails there. diff -r 7777f25d5266 -r 0d702ec77f0c net/resolvers/basic.lua --- a/net/resolvers/basic.lua Sat Nov 23 23:11:03 2019 +0100 +++ b/net/resolvers/basic.lua Sun Nov 24 04:23:51 2019 +0100 @@ -33,16 +33,6 @@ self:next(cb); end - local is_ip = inet_pton(self.hostname); - if is_ip then - if #is_ip == 16 then - cb(self.conn_type.."6", self.hostname, self.port, self.extra); - elseif #is_ip == 4 then - cb(self.conn_type.."4", self.hostname, self.port, self.extra); - end - return; - end - -- Resolve DNS to target list local dns_resolver = adns.resolver(); dns_resolver:lookup(function (answer) @@ -65,11 +55,24 @@ end local function new(hostname, port, conn_type, extra) + local ascii_host = idna_to_ascii(hostname); + local targets = nil; + + local is_ip = inet_pton(hostname); + if is_ip then + if #is_ip == 16 then + targets = { { conn_type.."6", hostname, port, extra } }; + elseif #is_ip == 4 then + targets = { { conn_type.."4", hostname, port, extra } }; + end + end + return setmetatable({ - hostname = idna_to_ascii(hostname); + hostname = ascii_host; port = port; conn_type = conn_type or "tcp"; extra = extra; + targets = targets; }, resolver_mt); end