From a2bf05deb4128d1526d8763dea3d734816e2ab5d Mon Sep 17 00:00:00 2001 From: Chris O'Hara Date: Sun, 13 Dec 2015 19:01:05 +1000 Subject: [PATCH] Allow triple hyphen in IDNA hostnames, closes #466 --- CHANGELOG.md | 5 +++++ test/validators.js | 1 + validator.js | 6 ++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73649c413..42238437c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +#### HEAD + +- Allow triple hyphens in IDNA hostnames + ([#466](https://github.com/chriso/validator.js/issues/466)) + #### 4.4.0 - Added `isMACAddress()` validator diff --git a/test/validators.js b/test/validators.js index c59f52e49..51a35b7f8 100644 --- a/test/validators.js +++ b/test/validators.js @@ -183,6 +183,7 @@ describe('Validators', function () { , 'http://foo--bar.com' , 'http://høyfjellet.no' , 'http://xn--j1aac5a4g.xn--j1amh' + , 'http://xn------eddceddeftq7bvv7c4ke4c.xn--p1ai' , 'http://кулік.укр' ] , invalid: [ diff --git a/validator.js b/validator.js index 3efb5ef38..c9b4e6986 100644 --- a/validator.js +++ b/validator.js @@ -399,8 +399,10 @@ // disallow full-width chars return false; } - if (part[0] === '-' || part[part.length - 1] === '-' || - part.indexOf('---') >= 0) { + if (part[0] === '-' || part[part.length - 1] === '-') { + return false; + } + if (part.indexOf('---') >= 0 && part.slice(0, 4) !== 'xn--') { return false; } }