Turns out the empty line is supposed to be the domain line for the localhost, but since tld.js doesn't recognize localhost as valid top level domain, the line is left empty.
tld.js behaviour is bit odd though, as the next tests show:
input ->
returns
"localhost" -> ""
"localhost:8000" -> ""
"
http://localhost" -> ""
"
http://localhost:8000" -> "
http://localhost:8000"
"foo.localhost" -> "foo.localhost"
"foo.localhost:8000" -> "foo.localhost:8000"
Luckily there appears to be an easy fix for our problem. Simply add one line as shown below.
Code: Select all
tld.js
getDomain(domain) {
if (domain == "localhost") return domain; // added line
if (this.isIp(domain)) return domain;
...
This should be OK as long as getDomain is fed only hostnames, so the port number or protocol are not going to be issues. Alternatively you could get fancy with regexps, or update the tld.js. The newer version seems to have feature to import custom hostnames like localhost.
Turns out the empty line is supposed to be the domain line for the localhost, but since tld.js doesn't recognize localhost as valid top level domain, the line is left empty.
tld.js behaviour is bit odd though, as the next tests show:
[b]input[/b] -> [b]returns[/b]
"localhost" -> ""
"localhost:8000" -> ""
"http://localhost" -> ""
"http://localhost:8000" -> "http://localhost:8000"
"foo.localhost" -> "foo.localhost"
"foo.localhost:8000" -> "foo.localhost:8000"
Luckily there appears to be an easy fix for our problem. Simply add one line as shown below.
[code]tld.js
getDomain(domain) {
if (domain == "localhost") return domain; // added line
if (this.isIp(domain)) return domain;
...[/code]
This should be OK as long as getDomain is fed only hostnames, so the port number or protocol are not going to be issues. Alternatively you could get fancy with regexps, or update the tld.js. The newer version seems to have feature to import custom hostnames like localhost.