Skip to content

Commit

Permalink
fix: fixed ip check ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed Mar 10, 2023
1 parent 9805dd1 commit ccdbeae
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ import('private-ip').then((obj) => {

// <https://github.com/szmarczak/cacheable-lookup/pull/76>
class Tangerine extends dns.promises.Resolver {
static HOSTFILE = hostile.get(true).join('\n');
static HOSTFILE = hostile
.get(true)
.map((s) => (Array.isArray(s) ? s.join(' ') : s))
.join('\n');

static HOSTS = new Hosts(
hostile
Expand Down Expand Up @@ -927,8 +930,6 @@ class Tangerine extends dns.promises.Resolver {
// edge case where localhost IP returns matches
if (!isPrivateIP) await pWaitFor(() => Boolean(isPrivateIP));

if (ip === '::1' || ip === '127.0.0.1') return [];

const answers = [];
const matches = [];

Expand All @@ -946,6 +947,9 @@ class Tangerine extends dns.promises.Resolver {
// if (answers.length > 0 || (matches.includes(ip) && isPrivateIP(ip)))
if (answers.length > 0 || matches.includes(ip)) return answers;

// NOTE: we can prob remove this (?)
if (ip === '::1' || ip === '127.0.0.1') return [];

// reverse the IP address
if (!dohdec) await pWaitFor(() => Boolean(dohdec));

Expand Down

0 comments on commit ccdbeae

Please sign in to comment.