Skip to content

Commit

Permalink
Minor refactoring of the toASCII function
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiSchwarz-cnic committed Feb 23, 2024
1 parent d6cd9a7 commit 8569350
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ function toASCII(domainName, {
transitionalProcessing,
ignoreInvalidPunycode
});

let labels = result.string.split(".");
labels = labels.map(l => {
if (containsNonASCII(l)) {
Expand All @@ -291,23 +292,23 @@ function toASCII(domainName, {
return l;
});

if (result.error) {
return null;
}

if (verifyDNSLength) {
const total = labels.join(".").length;
if (total > 253 || total === 0) {
result.error = true;
return null;
}

for (let i = 0; i < labels.length; ++i) {
if (labels[i].length > 63 || labels[i].length === 0) {
result.error = true;
break;
return null;
}
}
}

if (result.error) {
return null;
}
return labels.join(".");
}

Expand Down

0 comments on commit 8569350

Please sign in to comment.