From da488f02203e84e1881965c9c34064bcf9de07e7 Mon Sep 17 00:00:00 2001 From: Shivan Date: Sun, 20 Sep 2020 14:32:26 -0700 Subject: [PATCH] Add explanation and more special-use domains Fix #174 --- lib/permuteDomain.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/permuteDomain.js b/lib/permuteDomain.js index 78e6cad5..f402cea6 100644 --- a/lib/permuteDomain.js +++ b/lib/permuteDomain.js @@ -33,15 +33,27 @@ const pubsuffix = require("./pubsuffix-psl"); // Gives the permutation of all possible domainMatch()es of a given domain. The // array is in shortest-to-longest order. Handy for indexing. -const SPECIAL_USE_DOMAINS = ["local"]; // RFC 6761 + +// RFC 6761 +const SPECIAL_USE_DOMAINS = [ + "local", + "example", + "invalid", + "localhost", + "test" +]; + function permuteDomain(domain, allowSpecialUseDomain) { let pubSuf = null; if (allowSpecialUseDomain) { const domainParts = domain.split("."); - if (SPECIAL_USE_DOMAINS.includes(domainParts[domainParts.length - 1])) { - pubSuf = `${domainParts[domainParts.length - 2]}.${ - domainParts[domainParts.length - 1] - }`; + // If the right-most label in the name is a special-use domain (e.g. bananas.apple.localhost), + // then don't use PSL. This is because most special-use domains are not listed on PSL. + const topLevelDomain = domainParts[domainParts.length - 1]; + if (SPECIAL_USE_DOMAINS.includes(topLevelDomain)) { + const secondLevelDomain = domainParts[domainParts.length - 2]; + // In aforementioned example, the eTLD/pubSuf will be apple.localhost + pubSuf = `${secondLevelDomain}.${topLevelDomain}`; } else { pubSuf = pubsuffix.getPublicSuffix(domain); }