Skip to content

Commit

Permalink
Merge pull request #203 from salesforce/feat/special-use-domains
Browse files Browse the repository at this point in the history
Add explanation and more special-use domains
  • Loading branch information
ShivanKaul committed Oct 11, 2020
2 parents 0ccbbec + 30c1033 commit 1ac7c43
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions lib/permuteDomain.js
Expand Up @@ -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);
}
Expand Down

0 comments on commit 1ac7c43

Please sign in to comment.