Skip to content

Commit

Permalink
Fixed - Multi lines fix only to some TLDs
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiIgna committed May 16, 2020
1 parent a473eab commit 3b8238d
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 39 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Whoiser change log

#### 1.7.1 - 16 May 2020
- Fixed - Apply multi lines fix only for TLDs that need it

#### 1.7.0 - 16 May 2020
- Updated - Improved WHOIS parsing for multi line info (for .be, .eu domains and hopefully others)
- Updated - Detect & remove more redacted whois text
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "whoiser",
"version": "1.7.0",
"version": "1.7.1",
"description": "Whois info for TLDs, domains and IPs",
"keywords": [
"whois",
Expand Down
80 changes: 44 additions & 36 deletions src/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const parseSimpleWhois = whois => {
return data
}

const parseDomainWhois = whois => {
const parseDomainWhois = (domain, whois) => {
const noData = ['-', 'data protected', 'not disclosed', 'data redacted', 'not available', 'redacted for privacy', 'gdpr redacted', 'non-public data', 'gdpr masked', 'statutory masking enabled', 'redacted by privacy']
const renameLabels = {
'domain name': 'Domain Name',
Expand All @@ -130,6 +130,7 @@ const parseDomainWhois = whois => {
registrar: 'Registrar',
'registrar name': 'Registrar',
url: 'Registrar URL',
'registrar website': 'Registrar URL',
'creation date': 'Created Date',
'registered on': 'Created Date',
created: 'Created Date',
Expand Down Expand Up @@ -189,41 +190,9 @@ const parseDomainWhois = whois => {
.map(line => line.replace("\t", ' '))


// Fix "label: \n value" format
lines.forEach((line, index) => {

// if line is just a WHOIS label ending with ":", then verify next lines
if (!line.startsWith('*') && !line.startsWith('%') && line.trim().endsWith(':')) {
let addedLabel = false

// 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 (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] = ''
}
}
})
if (domain.endsWith('.be') || domain.endsWith('.eu')) {
lines = handleMultiLines(lines)
}

lines = lines.map(l => l.trim())

Expand Down Expand Up @@ -280,5 +249,44 @@ const parseDomainWhois = whois => {
return data
}

// Fix "label: \n value" format
const handleMultiLines = lines => {
lines.forEach((line, index) => {

// if line is just a WHOIS label ending with ":", then verify next lines
if (!line.startsWith('*') && !line.startsWith('%') && line.trim().endsWith(':')) {
let addedLabel = false

// 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 (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
}

module.exports.parseSimpleWhois = parseSimpleWhois
module.exports.parseDomainWhois = parseDomainWhois
2 changes: 1 addition & 1 deletion src/whoiser.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const whoisDomain = async (domain, { host = null, timeout = 15000, follow = 2, r

try {
resultRaw = await whoisQuery({ host, query, timeout })
result = parseDomainWhois(resultRaw)
result = parseDomainWhois(domain, resultRaw)
} catch (err) {
result = { error: err.message }
}
Expand Down

0 comments on commit 3b8238d

Please sign in to comment.