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

.domain() and Domain suffixes with two parts (i.e. co.uk) #17

Closed
wasimmer opened this issue Feb 14, 2012 · 6 comments
Closed

.domain() and Domain suffixes with two parts (i.e. co.uk) #17

wasimmer opened this issue Feb 14, 2012 · 6 comments

Comments

@wasimmer
Copy link

Technically, URI.js is most likely returning the correct value, however I was wondering how the following issue could be resolved most elegantly:

URI("http://amazon.co.uk").domain()
"co.uk"

... the value I was expecting was "amazon.co.uk".
So, whenever the suffix of a domain consists out of two parts (co.uk, com.tr) domain() returns a value which is not really expected/useful.
Any help for how to treat these composed domain suffixes would be appreciated. Thanks.

@rodneyrehm
Copy link
Member

I see your point. I must admit that I haven't thought about these xx.tld domains at all. Unless there is a table of second-level-domains (xx.tld), I wouldn't know how to make this happen. (subdomain.db.de here db.de is the actual domain.)

If anyone has any pointers, please let me know.

@rodneyrehm
Copy link
Member

A bit of research

still unclear

is every SLD-enabled TLD prohibiting 'foo.uk' in favor of 'foo.co.uk' or are SLD (sometimes?) only a suggestion? If there's a black 'n white "doing SLD completely or not at all", we might inverse the process to scanning for TLDs not enabling SLDs (~150 vs 1400). But then "virtual TLDs" (e.g. ''.dev' used by me for local development infrastructure) wouldn't apply anymore. So, pretty much not an option (for me) either. damn.

I'm certain I can convert that list of SLDs to some regexp and hook that into .domain() and .tld(). I'm not yet sure if I want to "break" current behavior, though. .tld() currently returns 'uk' for 'foo.co.uk' which may very well be what the implementor expected. If it were to return 'co.uk', how would the 'uk' part be accessed? The alternative would be adding new methods, which is not quite the way to go (for me) either.

I'll have to think about this some more…

@rodneyrehm
Copy link
Member

Second Level Domains are now properly handled by URI.js Version 1.5.0

var uri = URI("http://www.example.co.uk")
uri.domain() // returns "example.co.uk"
uri.domain(true) // returns "co.uk"
uri.tld() // returns "co.uk"
uri.tld(true) // returns "uk"
uri.tld("co.il") // allowed, since it's a known SLD
uri.tld("foo.bar") // setting TLD to "bar" since "foo.bar" is unknown

src/SecondLevelDomains.js contains a list of SLDs (imported from Gaving Miller's Second Level Domains List as well as some regular expressions for testing. This file needs to be loaded (before URI.js) to enable Second Level Domain support.

I hope this helps…

@wasimmer
Copy link
Author

works as expected, i.e. this is awesome! Thanks alot for looking into it!

@ulzee
Copy link

ulzee commented Mar 30, 2017

Felt I should post this here since I've run into a similar issue.

const uri = require('urijs');
const a = new uri('http://torrentz.eu.com');
console.log(a.domain());

The above code outputs eu.com, but I believe the correct result here should be torrentz.eu.com. What would it take to output the expected domain?

@rodneyrehm
Copy link
Member

@ul1994 I cloned that to #333, fixed the problem and released v1.18.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants