From ce4ea872859736d2b7566c8214e0005b46700063 Mon Sep 17 00:00:00 2001 From: frauri Date: Fri, 13 Jan 2023 09:45:18 +0100 Subject: [PATCH 1/2] Update parsers.js for better handle dot it --- src/parsers.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/parsers.js b/src/parsers.js index 0c26e34..da76976 100644 --- a/src/parsers.js +++ b/src/parsers.js @@ -280,6 +280,10 @@ const parseDomainWhois = (domain, whois) => { if (domain.endsWith('.jp')) { lines = handleJpLines(lines) } + + if (domain.endsWith('.it')) { + lines = handleDotIt(lines) + } lines = lines.map((l) => l.trim()) @@ -360,6 +364,40 @@ const handleDotUa = (lines) => { return lines } +const handleDotIt = (lines) => { + lines.forEach((line, index) => { + if (line == 'Registrar' || line == 'Nameservers') { + // Check next lines + for (let i = 1; i <= 5; i++) { + // if no line or empty line + if (!lines[index + i] || !lines[index + i].trim().length) { + break + } + + // if tabbed line or line with value only, prefix the line with main label + if ((lines[index + i].startsWith(' ') && lines[index + i].includes(': ')) || !lines[index + i].endsWith(':')) { + let label = line.trim() + if (label == 'Nameservers') { + label = "Name Server:" + } + + if (lines[index + i].includes(':') && label.endsWith(':')) { + label = label.slice(0, -1) + } + + lines[index + i] = label + ' ' + lines[index + i].replace('\t', ' ').trim() + addedLabel = true + } + } + // remove this line if it was just a label for other lines + if (addedLabel) { + lines[index] = '' + } + } + }) + return lines +} + // Fix "label: \n value" format const handleMultiLines = (lines) => { lines.forEach((line, index) => { From 7c93da6bc546dc01c13f1f89dc563211a4b3133b Mon Sep 17 00:00:00 2001 From: frauri Date: Fri, 13 Jan 2023 10:08:53 +0100 Subject: [PATCH 2/2] Added test for dot it --- test/domains.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/domains.js b/test/domains.js index 2da9a05..7838a8e 100644 --- a/test/domains.js +++ b/test/domains.js @@ -92,6 +92,13 @@ describe('#whoiser.domain()', function() { assert.notStrictEqual(whois['whois.ua']['administrative contacts organization-loc'], false, 'Does not return admin name') assert.notStrictEqual(whois['whois.ua']['technical contacts organization-loc'], false, 'Does not return tech name') }); + + it('returns WHOIS for "google.it"', async function() { + let whois = await whoiser.domain('google.it') + assert.equal(whois['whois.nic.it']['Domain Name'], 'google.it', 'Domain name doesn\'t match') + assert.equal(whois['whois.nic.it']['Name Server'].length, 4, 'Incorrect number of NS returned') + assert.equal(whois['whois.nic.it']['Registrar'], 'MarkMonitor International Limited MARKMONITOR-REG', 'Registrar name doesn\'t match') + }); }); });