Skip to content

Commit

Permalink
chore: replace punnyCode with node:url
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelSun90 committed Feb 2, 2024
1 parent 57998f2 commit 1362997
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/connector.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import net from 'net';
import dns, { type LookupAddress } from 'dns';

import * as punycode from 'punycode';
import url from 'node:url';
import { AbortSignal } from 'node-abort-controller';
import AbortError from './errors/abort-error';

Expand Down Expand Up @@ -167,7 +167,7 @@ export async function lookupAllAddresses(host: string, lookup: LookupFunction, s

signal.addEventListener('abort', onAbort);

lookup(punycode.toASCII(host), { all: true }, (err, addresses) => {
lookup(url.domainToASCII(host), { all: true }, (err, addresses) => {
signal.removeEventListener('abort', onAbort);

err ? reject(err) : resolve(addresses);
Expand Down
4 changes: 2 additions & 2 deletions src/sender.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dgram from 'dgram';
import dns from 'dns';
import net from 'net';
import * as punycode from 'punycode';
import url from 'node:url';
import { AbortSignal } from 'node-abort-controller';

import AbortError from './errors/abort-error';
Expand Down Expand Up @@ -83,7 +83,7 @@ export async function sendMessage(host: string, port: number, lookup: LookupFunc

signal.addEventListener('abort', onAbort);

lookup(punycode.toASCII(host), { all: true }, (err, addresses) => {
lookup(url.domainToASCII(host), { all: true }, (err, addresses) => {
signal.removeEventListener('abort', onAbort);

err ? reject(err) : resolve(addresses);
Expand Down
4 changes: 2 additions & 2 deletions test/unit/connector-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Mitm = require('mitm');
const sinon = require('sinon');
const punycode = require('punycode');
const url = require('node:url');
const assert = require('chai').assert;
const { AbortController } = require('node-abort-controller');
const AggregateError = require('es-aggregate-error');
Expand All @@ -27,7 +27,7 @@ describe('lookupAllAddresses', function() {
}

assert.isOk(lookup.called, 'Failed to call `lookup` function for hostname');
assert.isOk(lookup.calledWithMatch(punycode.toASCII(server)), 'Unexpected hostname passed to `lookup`');
assert.isOk(lookup.calledWithMatch(url.domainToASCII(server)), 'Unexpected hostname passed to `lookup`');
});

it('test ASCII Server name', async function() {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/instance-lookup-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const sinon = require('sinon');
const punycode = require('punycode');
const url = require('node:url');
const assert = require('chai').assert;
const dgram = require('dgram');
const { AbortController } = require('node-abort-controller');
Expand Down Expand Up @@ -361,7 +361,7 @@ describe('parseBrowserResponse', function() {
}

sinon.assert.calledOnce(lookup);
sinon.assert.calledWithMatch(lookup, punycode.toASCII(options.server));
sinon.assert.calledWithMatch(lookup, url.domainToASCII(options.server));
});

it('test ASCII Server name', async function() {
Expand Down

0 comments on commit 1362997

Please sign in to comment.