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

Tld #138

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Tld #138

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
4 changes: 3 additions & 1 deletion lib/clean-host.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ function checkTrimmingNeeded(value) {
* @param {string} value
*/
function checkLowerCaseNeeded(value) {
for (var i = 0; i < value.length; i += 1) {
let i = 0;
const m = value.length;
for (; i < m; i++) {
var code = value.charCodeAt(i);
if (code >= 65 && code <= 90) { // [A-Z]
return true;
Expand Down
17 changes: 13 additions & 4 deletions lib/is-valid.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,13 @@ module.exports = function isValid(hostname) {
var code;
var len = hostname.length;

for (var i = 0; i < len; i += 1) {
let i = 0;
let hasAlphaOrDigit = false;
for (; i < len; i++) {
code = hostname.charCodeAt(i);
const isAlphaOrDigit = isAlpha(code) || isDigit(code);
hasAlphaOrDigit |= isAlphaOrDigit;


if (code === 46) { // '.'
if (
Expand All @@ -72,21 +77,25 @@ module.exports = function isValid(hostname) {
// Check that previous character was not already a '.'
lastCharCode === 46 ||
// Check that the previous label does not end with a '-'
lastCharCode === 45
lastCharCode === 45 ||
// check that prvious label does not end with a '_'
lastCharCode === 95
) {
return false;
}

lastDotIndex = i;
} else if (!(isAlpha(code) || isDigit(code) || code === 45)) {
// Check if there is a forbidden character in the label: [^a-zA-Z0-9-]
} else if (!isAlphaOrDigit && !code === 45 && !code === 95) {
// Check if there is a forbidden character in the label: [^a-zA-Z0-9-_]
return false;
}

lastCharCode = code;
}

return (
// has atleast 1 digit or alpha character
hasAlphaOrDigit &&
// Check that last label is shorter than 63 chars
(len - lastDotIndex - 1) <= 63 &&
// Check that the last character is an allowed trailing label character.
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@
]
},
"dependencies": {
"punycode": "^2.0.0"
},
"devDependencies": {
"punycode": "^2.0.0",
"benchmark": "^2.1.4",
"browserify": "^17.0.1",
"env-test": "^1.0.0",
Expand Down
Loading