Skip to content

Commit

Permalink
fix(SLD): adding CentralNic SLDs - #333
Browse files Browse the repository at this point in the history
  • Loading branch information
rodneyrehm committed Mar 30, 2017
1 parent 230da87 commit 88f5a32
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 24 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

The release notes tracked in this document are also made available on the [releases page](https://github.com/medialize/URI.js/releases)

### master ###

* adding support for [CentralNic](https://en.wikipedia.org/wiki/CentralNic#Second-level_domains) Second Level Domains - [Issue #333](https://github.com/medialize/URI.js/issues/333)

### 1.18.9 (March 6th 2017) ###

* adding option `strict` to [`URITemplate()`](http://medialize.github.io/URI.js/uri-template.html) in order to throw an exception in case a placeholder could not be replaced - [PR #330](https://github.com/medialize/URI.js/issues/330)
Expand Down
7 changes: 6 additions & 1 deletion src/SecondLevelDomains.js
Expand Up @@ -173,7 +173,12 @@
'ye':' co com gov ltd me net org plc ',
'yu':' ac co edu gov org ',
'za':' ac agric alt bourse city co cybernet db edu gov grondar iaccess imt inca landesign law mil net ngo nis nom olivetti org pix school tm web ',
'zm':' ac co com edu gov net org sch '
'zm':' ac co com edu gov net org sch ',
// https://en.wikipedia.org/wiki/CentralNic#Second-level_domains
'com': 'ar br cn de eu gb gr hu jpn kr no qc ru sa se uk us uy za ',
'net': 'gb jp se uk ',
'org': 'ae',
'de': 'com '
},
// gorhill 2013-10-25: Using indexOf() instead Regexp(). Significant boost
// in both performance and memory footprint. No initialization required.
Expand Down
62 changes: 39 additions & 23 deletions test/test.js
Expand Up @@ -560,29 +560,20 @@

});
test('sld', function() {
// Lets just test them all..
// Calling URI.is(), URI.domain(), URI.subdomain() allows us to indirectly
// test SLD.has(), SLD.is() and SLD.get()
var u = new URI('http://www.example.org/foo.html');
equal(u.is('sld'), false, 'is not sld');
var list = SecondLevelDomains.list;
var tlds = Object.keys(list);
var iTld = tlds.length;
var tld, slds, sld, iSld;
while ( iTld-- ) {
tld = tlds[iTld];
slds = list[tld].trim().split(/\s+/);
iSld = slds.length;
while ( iSld-- ) {
sld = slds[iSld].trim() + '.' + tld;
u.hostname('www.example.' + sld);
equal(u.is('sld'), true, 'is sld');
equal(u.domain(), 'example.' + sld, 'domain is example.' + sld);
equal(u.subdomain(), 'www', 'subdomain is www');
u.hostname('www.example.' + tld);
equal(u.is('sld'), false, 'is not sld');
}
}
var u = new URI('http://www.example.ch/foo.html')
equal(u.is('sld'), false, 'is() www.example.ch');
equal(u.domain(), 'example.ch', 'domain() www.example.ch');
equal(u.subdomain(), 'www', 'subdomain() www.example.ch');

u = new URI('http://www.example.com/foo.html')
equal(u.is('sld'), false, 'is() www.example.com');
equal(u.domain(), 'example.com', 'domain() www.example.com');
equal(u.subdomain(), 'www', 'subdomain() www.example.com');

u = new URI('http://www.example.eu.com/foo.html')
equal(u.is('sld'), true, 'is() www.example.eu.com');
equal(u.domain(), 'example.eu.com', 'domain() www.example.eu.com');
equal(u.subdomain(), 'www', 'subdomain() www.example.eu.com');
});
test('directory', function() {
var u = new URI('http://www.example.org/some/directory/foo.html');
Expand Down Expand Up @@ -1855,4 +1846,29 @@
equal(URI.encodeReserved('ä:/?#[]@!$&\'()*+,;='), '%C3%A4:/?#[]@!$&\'()*+,;=');
});

module('SecondLevelDomains');
test('SecondLevelDomains.get()', function() {
equal(SecondLevelDomains.get('www.example.ch'), null, 'www.example.ch')
equal(SecondLevelDomains.get('www.example.com'), null, 'www.example.com')
equal(SecondLevelDomains.get('www.example.eu.com'), 'eu.com', 'www.example.eu.com')
equal(SecondLevelDomains.get('www.example.co.uk'), 'co.uk', 'www.example.co.uk')
});
test('SecondLevelDomains.has()', function() {
equal(SecondLevelDomains.has('www.example.ch'), false, 'www.example.ch')
equal(SecondLevelDomains.has('www.example.com'), false, 'www.example.com')
equal(SecondLevelDomains.has('www.example.eu.com'), true, 'www.example.eu.com')
equal(SecondLevelDomains.has('www.example.co.uk'), true, 'www.example.co.uk')
});
test('SecondLevelDomains.is()', function() {
equal(SecondLevelDomains.is('ch'), false, 'ch')
equal(SecondLevelDomains.is('example.ch'), false, 'example.ch')

equal(SecondLevelDomains.is('com'), false, 'com')
equal(SecondLevelDomains.is('eu.com'), true, 'eu.com')
equal(SecondLevelDomains.is('example.com'), false, 'example.com')

equal(SecondLevelDomains.is('uk'), false, 'uk')
equal(SecondLevelDomains.is('co.uk'), true, 'co.uk')
});

})();

0 comments on commit 88f5a32

Please sign in to comment.