Skip to content

Commit

Permalink
Merge pull request #92 from jonathansampson/master
Browse files Browse the repository at this point in the history
Fix #91
  • Loading branch information
AndreiIgna authored Feb 4, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 36ac7e1 + 0aecfd6 commit f7df16b
Showing 2 changed files with 39 additions and 28 deletions.
56 changes: 31 additions & 25 deletions src/parsers.js
Original file line number Diff line number Diff line change
@@ -376,37 +376,43 @@ const handleDotUa = (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
}
let section = ''
const replacement = []

// 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:"
}
for (let line of lines) {
// Ignore comments and empty lines
if (line.startsWith('*') || line === '') {
continue
}

if (lines[index + i].includes(':') && label.endsWith(':')) {
label = label.slice(0, -1)
}
// Collapse whitespace
const collapsed = line.replace(/\s+/g, ' ').trim()

lines[index + i] = label + ' ' + lines[index + i].replace('\t', ' ').trim()
addedLabel = true
// Check for top-level values and new section indicators
if (/^[^\s]/.test(line)) {
if (line.includes(':')) {
replacement.push(collapsed)
} else {
// Special handling for "Nameservers" section
if (line === 'Nameservers') {
section = 'Name Server:'
} else {
section = collapsed
}
}
// remove this line if it was just a label for other lines
if (addedLabel) {
lines[index] = ''
}
}
})
return lines

// Make sure sub-section lines are properly labeled
if (/^\s{2}[^\s]/.test(line)) {
// New sub-section
replacement.push(`${section} ${collapsed}`)
} else if (/^\s{4}/.test(line)) {
// Continuation of previous line
replacement[replacement.length - 1] += `, ${collapsed}`
}
}

return replacement
}

// Fix "label: \n value" format
11 changes: 8 additions & 3 deletions test/domains.js
Original file line number Diff line number Diff line change
@@ -100,13 +100,18 @@ 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() {

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')
});
assert.equal(whois['whois.nic.it']['Created Date'], '1999-12-10 00:00:00', 'Creation date doesn\'t match')
for (const property of ['Registrant', 'Admin Contact', 'Technical Contacts']) {
const label = `${property} Created`
assert.equal(typeof whois['whois.nic.it'][label], 'string', `${label} does not exist, or is not a string`)
}
})
});

});

0 comments on commit f7df16b

Please sign in to comment.