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

Fails for country specific TLDs #3

Closed
eduardocereto opened this issue Oct 28, 2012 · 14 comments
Closed

Fails for country specific TLDs #3

eduardocereto opened this issue Oct 28, 2012 · 14 comments

Comments

@eduardocereto
Copy link

$.url('host', 'http://www.google.com.br')
> "com.br"
$.url('sub', 'http://www.google.com.br')
> "www.google"
$.url('tld', 'http://www.google.com.br')
> "br"
@websanova
Copy link
Owner

This is a tricky one, may leave this for a separate "heavyweight" version.

@websanova websanova reopened this Oct 28, 2012
@nelix
Copy link

nelix commented Oct 29, 2012

This is a pretty big deal.
Take a peek at suffix.js for a solution. It's not as pretty as what you have though.

@waawal
Copy link

waawal commented Nov 1, 2012

👍

Most browsers uses the list at http://publicsuffix.org/

@46bit
Copy link

46bit commented Nov 6, 2012

New to this project, but quite interested so thought I'd contribute some thoughts.

waawii: Thanks for the publicsuffix.org link.

nelix: The simple approach of including all relevant TLDs would add 94KB, if we converted publicsuffix to a Javascript array. That's only 29KB after gzip, but it does somewhat weaken the lightweight aspect.

The first optimization that comes to mind would be to store the TLDs in a hierarchy, but the space saving is probably not too significant (will report back on this if I get a spare half hour).
[..., "uk", "mil.uk", "ac.uk", ...]
VS
[..., "uk": ["mil", "ac"], ...]

@eduardocereto
Copy link
Author

I have a solution that only works for the current url, not any arbitrary url. It exploits the fact that browsers can't set cookies for TLDs. I try to set a cookie until I can and that's the host. From there you can easily infer the sub and tld

https://gist.github.com/3043239

It only works for the current url because of course you can't set cookies for third party domains so you can't use this method.

@mattes
Copy link

mattes commented Feb 19, 2013

This is a pretty big deal.

+1

@mattes
Copy link

mattes commented Feb 19, 2013

https://github.com/oncletom/tld.js

Handful API to do stuff with domain names and URIs: validity, public etc.

Its main purpose is to check if a domain name is valid upon. 2 constraints:

an up-to-date TLDs database
must work in node.js and the browser
It is based on the public suffix list provided by Mozilla. Thanks Mozilla!

@origal
Copy link

origal commented Jun 26, 2014

Hey, Is there a generic solution for this issue?

$.url("domain","http://www.rest.co.il/sites/Default.asp?txtRestID=15455");

outputs: "co.il" instead of "rest.co.il".

@gorhill
Copy link

gorhill commented Jun 26, 2014

outputs: "co.il" instead of "rest.co.il"

That's the expected result, I don't see co.il in the public suffix list.

@origal
Copy link

origal commented Jun 26, 2014

Hmm.. How is .co.il not in the public suffix list and .co.uk, for example, is? Both are second level domains, what's the difference?

@gorhill
Copy link

gorhill commented Jun 26, 2014

Sorry, you are right, I just realize there is this entry: *.il, which confirms that indeed co.il should be seen as an effective TLD (I was searching for co.il specifically). I made a library which would return you the proper result: https://github.com/gorhill/publicsuffixlist.js (you need to feed it the list though).

@ssreekanth
Copy link

@websanova, are you planning to handle this issue? do you care to integrate your library with tld.js or publicsuffixlist.js (from the earlier comments), they both handle the country specific tlds? Thanks for the wonderful url parser library..

@websanova
Copy link
Owner

I'm currently preoccupied with work and a side project now so don't have
too much time to look into it. However would be good to make it some kind
of optional include if anyone is interested in integrating.
On May 13, 2015 09:31, "Sreekanth S" notifications@github.com wrote:

@websanova https://github.com/websanova, are you planning to handle
this issue? do you care to integrate your library with tld.js or
publicsuffixlist.js (from the earlier comments), they both handle the
country specific tlds? Thanks for the wonderful url parser library..


Reply to this email directly or view it on GitHub
#3 (comment).

@websanova
Copy link
Owner

Added support for this. Comes in two versions now url-tld.min.js and url.min.js. The tld version is about twice the size since it contains a hard coded list of tld's. Not sure if it contains all of them, as I just copy and paste this off stackoverflow. Let me know if any are missing and I will add them.

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

9 participants