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

[READY] tldjs gives inconsistent results #35

Merged
merged 5 commits into from
Jan 17, 2014
Merged
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
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ language: "node_js"
node_js:
- "0.8"
- "0.10"

cache:
directories:
- node_modules

notifications:
email:
on_success: change
on_failure: change

before_script:
- npm run build
12 changes: 7 additions & 5 deletions lib/tld.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ tld.getCandidateRule = function getCandidateRule (host, rules) {
rules.some(function (r) {
var pattern;

//sld matching? escape the loop immediately (except if it's an exception)
// sld matching? escape the loop immediately (except if it's an exception)
if ('.' + host === r.getNormalXld()) {
if (r.exception === true) {
rule.normal = r;
Expand All @@ -40,8 +40,8 @@ tld.getCandidateRule = function getCandidateRule (host, rules) {
return true;
}

//otherwise check as a complete host
//if it's an exception, we want to loop a bit more to a normal rule
// otherwise check as a complete host
// if it's an exception, we want to loop a bit more to a normal rule
pattern = '.+' + r.getNormalPattern() + '$';

if ((new RegExp(pattern)).test(host)) {
Expand All @@ -52,9 +52,11 @@ tld.getCandidateRule = function getCandidateRule (host, rules) {
return false;
});

//if there is an exception, we challenge its rules without changing pattern
// favouring the exception if encountered
// previously we were copy-altering a rule, creating inconsistent results based on rule order order
// @see https://github.com/oncletom/tld.js/pull/35
if (rule.normal && rule.exception) {
rule.normal.wildcard = rule.exception.wildcard;
return rule.exception;
}

return rule.normal;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"test": "npm run lint && npm run test-node",
"lint": "jshint --config .jshintrc lib/**/*.js",
"test-node": "mocha --reporter dot",
"test-watch": "mocha --reporter dot --watch",
"test-browser": "testling",
"build": "npm run build-rules && npm run build-browser && npm run build-compress",
"build-rules": "grunt update",
Expand Down
11 changes: 11 additions & 0 deletions test/tld.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ describe('tld.js', function () {
it('should not break on specific RegExp characters', function () {
expect(tld.getDomain('www.weir)domain.com')).to.equal('weir)domain.com');
});

it('should provide consistent results', function(){
expect(tld.getDomain('www.bl.uk')).to.equal('bl.uk');
expect(tld.getDomain('www.majestic12.co.uk')).to.equal('majestic12.co.uk');
});
});

describe('tldExists method', function () {
Expand Down Expand Up @@ -124,5 +129,11 @@ describe('tld.js', function () {
it('should not break on specific RegExp characters', function () {
expect(tld.getSubdomain('www.weir)domain.com')).to.equal('www');
});

//@see https://github.com/oncletom/tld.js/issues/35
it('should provide consistent results', function(){
expect(tld.getSubdomain('www.bl.uk')).to.equal('www');
expect(tld.getSubdomain('www.majestic12.co.uk')).to.equal('www');
});
});
});