Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved parser for TLD .it #84

Merged
merged 2 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down Expand Up @@ -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) => {
Expand Down
7 changes: 7 additions & 0 deletions test/domains.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
});
});

});