5 ms·
Extracting Host, Subdomain and TLD from a url is hard. And they clearly oversimplified it. $.url('host', 'http://www.google.com.br'); // 'com.br' $.url('s
by dudus 14y ago
Extracting Host, Subdomain and TLD from a url is hard. And they clearly oversimplified it.
$.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'
It will work for simple cases where the TLD has only one field like (www.google.com) or (www.usa.gov), but it will fail for any other tld with country codes.
- mistercow 14y agoThat is partially incorrect. There is no such thing as a TLD with more than one field. In "http://www.google.com.br http://www.google.com.br, "br" is, in fact, the TLD, while "com" is the SLD[1]. So the 'tld' behavior is fine. The "sub" behavior is awkward, however. It would make more sense to just have a numeric way of accessing the domain parts by index, just like they do with extracting the path elements. As for "host", well that is just completely the wrong behavior. Since the parameter is "host", you would expect that to give the hostname. But the hostname corresponding to an internet URL is simply the fully qualified domain name. I have no idea how the behavior implemented would be useful in the first place, but it certainly shouldn't be called "host". [1] http://en.wikipedia.org/wiki/Country_code_second-level_domain http://en.wikipedia.org/wiki/Country_code_second-level_domai...
- deleted 14y ago[deleted]
- mistercow 14y ago>I loathe this pedantry worlds more than I loathe pg's observed "midbrow dismissal". It's not pedantry. The feature is called "tld", and its functionality should reflect the actual definition of a TLD. Since dudus' comment also contained useful criticism (which I was careful to point out and expand on), it is entirely plausible that the creator of this project (or someone else doing something with TLDs) might take all of it to heart. Since the exact definition of a TLD is (as this discussion shows) a bit subtle and potentially confusing, it would be a Bad Thing for people to start implementing behaviors where the wrong definition was used. It would muddy the waters more and lead to more confusion about the precise meaning of TLD in the future. >This is probably, and I'm writing this confidently and without exaggeration, the worst experience one can have socially. I've fantasized about killing pedants, and I am not ashamed to admit it. My comment was constructive and I was careful not to be mean about it. Your comment was pointless, mean, and actually threatening. Maybe you should do a little self-examination here?
- deleted 14y ago[deleted]
- snowwolf 14y agoDomain parsing is hard. PublicSuffix service seems to be the best way of doing it. http://stackoverflow.com/questions/288810/get-the-subdomain-from-a-url http://stackoverflow.com/questions/288810/get-the-subdomain-...