Skip to content

Instantly share code, notes, and snippets.

@lorenzoongithub
Last active August 29, 2015 14:22
Show Gist options
  • Save lorenzoongithub/6f6066cf3a5a87f21275 to your computer and use it in GitHub Desktop.
Save lorenzoongithub/6f6066cf3a5a87f21275 to your computer and use it in GitHub Desktop.
uri.js
//
// URI.js is a javascript library for working with URLs
// http://medialize.github.io/URI.js/
//
load('https://cdnjs.cloudflare.com/ajax/libs/URI.js/1.15.2/URI.min.js');
u = new URI("http://www.example.org");
if (u.protocol() !== "http") throw "";
if (u.username() !== "") throw "";
if (u.password() !== "") throw "";
if (u.port() !== "") throw "";
if (u.path() !== "/") throw "";
if (u.query() !== "") throw "";
if (u.fragment() !== "") throw "";
if (u.resource() !== "/") throw "";
if (u.authority() !== "www.example.org") throw "";
if (u.userinfo() !== "") throw "";
if (u.subdomain() !== "www") throw "";
if (u.domain() !== "example.org") throw "";
if (u.tld() !== "org") throw "";
if (u.directory() !== "/") throw "";
if (u.filename() !== "") throw "";
if (u.suffix() !== "") throw "";
if (u.hash() !== "") throw "";
if (u.search() !== "") throw "";
if (u.host() !== "www.example.org") throw "";
if (u.hostname() !== "www.example.org") throw "";
u = new URI("http://www.example.co.uk");
if (u.protocol() !== "http") throw "";
if (u.username() !== "") throw "";
if (u.password() !== "") throw "";
if (u.port() !== "") throw "";
if (u.path() !== "/") throw "";
if (u.query() !== "") throw "";
if (u.fragment() !== "") throw "";
if (u.resource() !== "/") throw "";
if (u.authority() !== "www.example.co.uk") throw "";
if (u.userinfo() !== "") throw "";
if (u.subdomain() !== "www") throw "";
if (u.domain() !== "example.co.uk") throw "";
if (u.tld() !== "co.uk") throw "";
if (u.directory() !== "/") throw "";
if (u.filename() !== "") throw "";
if (u.suffix() !== "") throw "";
if (u.hash() !== "") throw "";
if (u.search() !== "") throw "";
if (u.host() !== "www.example.co.uk") throw "";
if (u.hostname() !== "www.example.co.uk") throw "";
u = new URI("http://www.example.org/some/directory/file.html?query=string#fragment");
if (u.protocol() !== "http") throw "";
if (u.username() !== "") throw "";
if (u.password() !== "") throw "";
if (u.port() !== "") throw "";
if (u.path() !== "/some/directory/file.html") throw "";
if (u.query() !== "query=string") throw "";
if (u.fragment() !== "fragment") throw "";
if (u.resource() !== "/some/directory/file.html?query=string#fragment") throw "";
if (u.authority() !== "www.example.org") throw "";
if (u.userinfo() !== "") throw "";
if (u.subdomain() !== "www") throw "";
if (u.domain() !== "example.org") throw "";
if (u.tld() !== "org") throw "";
if (u.directory() !== "/some/directory") throw "";
if (u.filename() !== "file.html") throw "";
if (u.suffix() !== "html") throw "";
if (u.hash() !== "#fragment") throw "";
if (u.search() !== "?query=string") throw "";
if (u.host() !== "www.example.org") throw "";
if (u.hostname() !== "www.example.org") throw "";
u = new URI("http://www.example.org/some/directory/file.html-is-awesome?query=string#fragment");
if (u.protocol() !== "http") throw "";
if (u.username() !== "") throw "";
if (u.password() !== "") throw "";
if (u.port() !== "") throw "";
if (u.path() !== "/some/directory/file.html-is-awesome") throw "";
if (u.query() !== "query=string") throw "";
if (u.fragment() !== "fragment") throw "";
if (u.resource() !== "/some/directory/file.html-is-awesome?query=string#fragment") throw "";
if (u.authority() !== "www.example.org") throw "";
if (u.userinfo() !== "") throw "";
if (u.subdomain() !== "www") throw "";
if (u.domain() !== "example.org") throw "";
if (u.tld() !== "org") throw "";
if (u.directory() !== "/some/directory") throw "";
if (u.filename() !== "file.html-is-awesome") throw "";
if (u.suffix() !== "") throw "";
if (u.hash() !== "#fragment") throw "";
if (u.search() !== "?query=string") throw "";
if (u.host() !== "www.example.org") throw "";
if (u.hostname() !== "www.example.org") throw "";
u = new URI("scheme://user:[email protected]:123/some/directory/file.html?query=string#fragment");
if (u.protocol() !== "scheme") throw "";
if (u.username() !== "user") throw "";
if (u.password() !== "pass") throw "";
if (u.port() !== "123") throw "";
if (u.path() !== "/some/directory/file.html") throw "";
if (u.query() !== "query=string") throw "";
if (u.fragment() !== "fragment") throw "";
if (u.resource() !== "/some/directory/file.html?query=string#fragment") throw "";
if (u.authority() !== "user:[email protected]:123") throw "";
if (u.userinfo() !== "user:pass") throw "";
if (u.subdomain() !== "www") throw "";
if (u.domain() !== "example.org") throw "";
if (u.tld() !== "org") throw "";
if (u.directory() !== "/some/directory") throw "";
if (u.filename() !== "file.html") throw "";
if (u.suffix() !== "html") throw "";
if (u.hash() !== "#fragment") throw "";
if (u.search() !== "?query=string") throw "";
if (u.host() !== "www.example.org:123") throw "";
if (u.hostname() !== "www.example.org") throw "";
u = new URI("scheme://user:pass:[email protected]/");
if (u.protocol() !== "scheme") throw "";
if (u.username() !== "user") throw "";
if (u.password() !== "pass:word") throw "";
if (u.port() !== "") throw "";
if (u.path() !== "/") throw "";
if (u.query() !== "") throw "";
if (u.fragment() !== "") throw "";
if (u.resource() !== "/") throw "";
if (u.authority() !== "user:pass%[email protected]") throw "";
if (u.userinfo() !== "user:pass%3Aword") throw "";
if (u.subdomain() !== "www") throw "";
if (u.domain() !== "example.org") throw "";
if (u.tld() !== "org") throw "";
if (u.directory() !== "/") throw "";
if (u.filename() !== "") throw "";
if (u.suffix() !== "") throw "";
if (u.hash() !== "") throw "";
if (u.search() !== "") throw "";
if (u.host() !== "www.example.org") throw "";
if (u.hostname() !== "www.example.org") throw "";
u = new URI("scheme://[email protected]:pass:[email protected]/");
if (u.protocol() !== "scheme") throw "";
if (u.username() !== "[email protected]") throw "";
if (u.password() !== "pass:word") throw "";
if (u.port() !== "") throw "";
if (u.path() !== "/") throw "";
if (u.query() !== "") throw "";
if (u.fragment() !== "") throw "";
if (u.resource() !== "/") throw "";
if (u.authority() !== "john%40doe.com:pass%[email protected]") throw "";
if (u.userinfo() !== "john%40doe.com:pass%3Aword") throw "";
if (u.subdomain() !== "www") throw "";
if (u.domain() !== "example.org") throw "";
if (u.tld() !== "org") throw "";
if (u.directory() !== "/") throw "";
if (u.filename() !== "") throw "";
if (u.suffix() !== "") throw "";
if (u.hash() !== "") throw "";
if (u.search() !== "") throw "";
if (u.host() !== "www.example.org") throw "";
if (u.hostname() !== "www.example.org") throw "";
u = new URI("/some/directory/file.html?query=string#fragment");
if (u.protocol() !== "") throw "";
if (u.username() !== "") throw "";
if (u.password() !== "") throw "";
if (u.port() !== "") throw "";
if (u.path() !== "/some/directory/file.html") throw "";
if (u.query() !== "query=string") throw "";
if (u.fragment() !== "fragment") throw "";
if (u.resource() !== "/some/directory/file.html?query=string#fragment") throw "";
if (u.authority() !== "") throw "";
if (u.userinfo() !== "") throw "";
if (u.subdomain() !== "") throw "";
if (u.domain() !== "") throw "";
if (u.tld() !== "") throw "";
if (u.directory() !== "/some/directory") throw "";
if (u.filename() !== "file.html") throw "";
if (u.suffix() !== "html") throw "";
if (u.hash() !== "#fragment") throw "";
if (u.search() !== "?query=string") throw "";
if (u.host() !== "") throw "";
if (u.hostname() !== "") throw "";
u = new URI("../some/directory/file.html?query=string#fragment");
if (u.protocol() !== "") throw "";
if (u.username() !== "") throw "";
if (u.password() !== "") throw "";
if (u.port() !== "") throw "";
if (u.path() !== "../some/directory/file.html") throw "";
if (u.query() !== "query=string") throw "";
if (u.fragment() !== "fragment") throw "";
if (u.resource() !== "../some/directory/file.html?query=string#fragment") throw "";
if (u.authority() !== "") throw "";
if (u.userinfo() !== "") throw "";
if (u.subdomain() !== "") throw "";
if (u.domain() !== "") throw "";
if (u.tld() !== "") throw "";
if (u.directory() !== "../some/directory") throw "";
if (u.filename() !== "file.html") throw "";
if (u.suffix() !== "html") throw "";
if (u.hash() !== "#fragment") throw "";
if (u.search() !== "?query=string") throw "";
if (u.host() !== "") throw "";
if (u.hostname() !== "") throw "";
u = new URI("user:[email protected]:123/some/directory/file.html?query=string#fragment");
if (u.protocol() !== "user") throw "";
if (u.username() !== "") throw "";
if (u.password() !== "") throw "";
if (u.port() !== "") throw "";
if (u.path() !== "[email protected]:123/some/directory/file.html") throw "";
if (u.query() !== "query=string") throw "";
if (u.fragment() !== "fragment") throw "";
if (u.resource() !== "[email protected]:123/some/directory/file.html?query=string#fragment") throw "";
if (u.authority() !== "") throw "";
if (u.userinfo() !== "") throw "";
if (u.subdomain() !== "") throw "";
if (u.domain() !== "") throw "";
if (u.tld() !== "") throw "";
if (u.directory() !== "") throw "";
if (u.filename() !== "") throw "";
if (u.suffix() !== "") throw "";
if (u.hash() !== "#fragment") throw "";
if (u.search() !== "?query=string") throw "";
if (u.host() !== "") throw "";
if (u.hostname() !== "") throw "";
u = new URI("://user:[email protected]:123/some/directory/file.html?query=string#fragment");
if (u.protocol() !== "") throw "";
if (u.username() !== "user") throw "";
if (u.password() !== "pass") throw "";
if (u.port() !== "123") throw "";
if (u.path() !== "/some/directory/file.html") throw "";
if (u.query() !== "query=string") throw "";
if (u.fragment() !== "fragment") throw "";
if (u.resource() !== "/some/directory/file.html?query=string#fragment") throw "";
if (u.authority() !== "user:[email protected]:123") throw "";
if (u.userinfo() !== "user:pass") throw "";
if (u.subdomain() !== "") throw "";
if (u.domain() !== "example.org") throw "";
if (u.tld() !== "org") throw "";
if (u.directory() !== "/some/directory") throw "";
if (u.filename() !== "file.html") throw "";
if (u.suffix() !== "html") throw "";
if (u.hash() !== "#fragment") throw "";
if (u.search() !== "?query=string") throw "";
if (u.host() !== "example.org:123") throw "";
if (u.hostname() !== "example.org") throw "";
u = new URI("//www.example.org/");
if (u.protocol() !== "") throw "";
if (u.username() !== "") throw "";
if (u.password() !== "") throw "";
if (u.port() !== "") throw "";
if (u.path() !== "/") throw "";
if (u.query() !== "") throw "";
if (u.fragment() !== "") throw "";
if (u.resource() !== "/") throw "";
if (u.authority() !== "www.example.org") throw "";
if (u.userinfo() !== "") throw "";
if (u.subdomain() !== "www") throw "";
if (u.domain() !== "example.org") throw "";
if (u.tld() !== "org") throw "";
if (u.directory() !== "/") throw "";
if (u.filename() !== "") throw "";
if (u.suffix() !== "") throw "";
if (u.hash() !== "") throw "";
if (u.search() !== "") throw "";
if (u.host() !== "www.example.org") throw "";
if (u.hostname() !== "www.example.org") throw "";
u = new URI("http://user:[email protected]:123/some/directory/file.html?query=string#fragment");
if (u.protocol() !== "http") throw "";
if (u.username() !== "user") throw "";
if (u.password() !== "pass") throw "";
if (u.port() !== "123") throw "";
if (u.path() !== "/some/directory/file.html") throw "";
if (u.query() !== "query=string") throw "";
if (u.fragment() !== "fragment") throw "";
if (u.resource() !== "/some/directory/file.html?query=string#fragment") throw "";
if (u.authority() !== "user:[email protected]:123") throw "";
if (u.userinfo() !== "user:pass") throw "";
if (u.subdomain() !== "") throw "";
if (u.domain() !== "") throw "";
if (u.tld() !== "") throw "";
if (u.directory() !== "/some/directory") throw "";
if (u.filename() !== "file.html") throw "";
if (u.suffix() !== "html") throw "";
if (u.hash() !== "#fragment") throw "";
if (u.search() !== "?query=string") throw "";
if (u.host() !== "123.123.123.123:123") throw "";
if (u.hostname() !== "123.123.123.123") throw "";
u = new URI("http://user:pass@fe80:0000:0000:0000:0204:61ff:fe9d:f156/some/directory/file.html?query=string#fragment");
if (u.protocol() !== "http") throw "";
if (u.username() !== "user") throw "";
if (u.password() !== "pass") throw "";
if (u.port() !== "") throw "";
if (u.path() !== "/some/directory/file.html") throw "";
if (u.query() !== "query=string") throw "";
if (u.fragment() !== "fragment") throw "";
if (u.resource() !== "/some/directory/file.html?query=string#fragment") throw "";
if (u.authority() !== "user:pass@[fe80:0000:0000:0000:0204:61ff:fe9d:f156]") throw "";
if (u.userinfo() !== "user:pass") throw "";
if (u.subdomain() !== "") throw "";
if (u.domain() !== "") throw "";
if (u.tld() !== "") throw "";
if (u.directory() !== "/some/directory") throw "";
if (u.filename() !== "file.html") throw "";
if (u.suffix() !== "html") throw "";
if (u.hash() !== "#fragment") throw "";
if (u.search() !== "?query=string") throw "";
if (u.host() !== "[fe80:0000:0000:0000:0204:61ff:fe9d:f156]") throw "";
if (u.hostname() !== "fe80:0000:0000:0000:0204:61ff:fe9d:f156") throw "";
u = new URI("http://user:pass@[fe80:0000:0000:0000:0204:61ff:fe9d:f156]:123/some/directory/file.html?query=string#fragment");
if (u.protocol() !== "http") throw "";
if (u.username() !== "user") throw "";
if (u.password() !== "pass") throw "";
if (u.port() !== "123") throw "";
if (u.path() !== "/some/directory/file.html") throw "";
if (u.query() !== "query=string") throw "";
if (u.fragment() !== "fragment") throw "";
if (u.resource() !== "/some/directory/file.html?query=string#fragment") throw "";
if (u.authority() !== "user:pass@[fe80:0000:0000:0000:0204:61ff:fe9d:f156]:123") throw "";
if (u.userinfo() !== "user:pass") throw "";
if (u.subdomain() !== "") throw "";
if (u.domain() !== "") throw "";
if (u.tld() !== "") throw "";
if (u.directory() !== "/some/directory") throw "";
if (u.filename() !== "file.html") throw "";
if (u.suffix() !== "html") throw "";
if (u.hash() !== "#fragment") throw "";
if (u.search() !== "?query=string") throw "";
if (u.host() !== "[fe80:0000:0000:0000:0204:61ff:fe9d:f156]:123") throw "";
if (u.hostname() !== "fe80:0000:0000:0000:0204:61ff:fe9d:f156") throw "";
u = new URI("http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html");
if (u.protocol() !== "http") throw "";
if (u.username() !== "") throw "";
if (u.password() !== "") throw "";
if (u.port() !== "80") throw "";
if (u.path() !== "/index.html") throw "";
if (u.query() !== "") throw "";
if (u.fragment() !== "") throw "";
if (u.resource() !== "/index.html") throw "";
if (u.authority() !== "[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80") throw "";
if (u.userinfo() !== "") throw "";
if (u.subdomain() !== "") throw "";
if (u.domain() !== "") throw "";
if (u.tld() !== "") throw "";
if (u.directory() !== "/") throw "";
if (u.filename() !== "index.html") throw "";
if (u.suffix() !== "html") throw "";
if (u.hash() !== "") throw "";
if (u.search() !== "") throw "";
if (u.host() !== "[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80") throw "";
if (u.hostname() !== "FEDC:BA98:7654:3210:FEDC:BA98:7654:3210") throw "";
u = new URI("http://[1080:0:0:0:8:800:200C:417A]/index.html");
if (u.protocol() !== "http") throw "";
if (u.username() !== "") throw "";
if (u.password() !== "") throw "";
if (u.port() !== "") throw "";
if (u.path() !== "/index.html") throw "";
if (u.query() !== "") throw "";
if (u.fragment() !== "") throw "";
if (u.resource() !== "/index.html") throw "";
if (u.authority() !== "[1080:0:0:0:8:800:200C:417A]") throw "";
if (u.userinfo() !== "") throw "";
if (u.subdomain() !== "") throw "";
if (u.domain() !== "") throw "";
if (u.tld() !== "") throw "";
if (u.directory() !== "/") throw "";
if (u.filename() !== "index.html") throw "";
if (u.suffix() !== "html") throw "";
if (u.hash() !== "") throw "";
if (u.search() !== "") throw "";
if (u.host() !== "[1080:0:0:0:8:800:200C:417A]") throw "";
if (u.hostname() !== "1080:0:0:0:8:800:200C:417A") throw "";
u = new URI("http://[3ffe:2a00:100:7031::1]");
if (u.protocol() !== "http") throw "";
if (u.username() !== "") throw "";
if (u.password() !== "") throw "";
if (u.port() !== "") throw "";
if (u.path() !== "/") throw "";
if (u.query() !== "") throw "";
if (u.fragment() !== "") throw "";
if (u.resource() !== "/") throw "";
if (u.authority() !== "[3ffe:2a00:100:7031::1]") throw "";
if (u.userinfo() !== "") throw "";
if (u.subdomain() !== "") throw "";
if (u.domain() !== "") throw "";
if (u.tld() !== "") throw "";
if (u.directory() !== "/") throw "";
if (u.filename() !== "") throw "";
if (u.suffix() !== "") throw "";
if (u.hash() !== "") throw "";
if (u.search() !== "") throw "";
if (u.host() !== "[3ffe:2a00:100:7031::1]") throw "";
if (u.hostname() !== "3ffe:2a00:100:7031::1") throw "";
u = new URI("http://[1080::8:800:200C:417A]/foo");
if (u.protocol() !== "http") throw "";
if (u.username() !== "") throw "";
if (u.password() !== "") throw "";
if (u.port() !== "") throw "";
if (u.path() !== "/foo") throw "";
if (u.query() !== "") throw "";
if (u.fragment() !== "") throw "";
if (u.resource() !== "/foo") throw "";
if (u.authority() !== "[1080::8:800:200C:417A]") throw "";
if (u.userinfo() !== "") throw "";
if (u.subdomain() !== "") throw "";
if (u.domain() !== "") throw "";
if (u.tld() !== "") throw "";
if (u.directory() !== "/") throw "";
if (u.filename() !== "foo") throw "";
if (u.suffix() !== "") throw "";
if (u.hash() !== "") throw "";
if (u.search() !== "") throw "";
if (u.host() !== "[1080::8:800:200C:417A]") throw "";
if (u.hostname() !== "1080::8:800:200C:417A") throw "";
u = new URI("http://[::192.9.5.5]/ipng");
if (u.protocol() !== "http") throw "";
if (u.username() !== "") throw "";
if (u.password() !== "") throw "";
if (u.port() !== "") throw "";
if (u.path() !== "/ipng") throw "";
if (u.query() !== "") throw "";
if (u.fragment() !== "") throw "";
if (u.resource() !== "/ipng") throw "";
if (u.authority() !== "[::192.9.5.5]") throw "";
if (u.userinfo() !== "") throw "";
if (u.subdomain() !== "") throw "";
if (u.domain() !== "") throw "";
if (u.tld() !== "") throw "";
if (u.directory() !== "/") throw "";
if (u.filename() !== "ipng") throw "";
if (u.suffix() !== "") throw "";
if (u.hash() !== "") throw "";
if (u.search() !== "") throw "";
if (u.host() !== "[::192.9.5.5]") throw "";
if (u.hostname() !== "::192.9.5.5") throw "";
u = new URI("http://[::FFFF:129.144.52.38]:80/index.html");
if (u.protocol() !== "http") throw "";
if (u.username() !== "") throw "";
if (u.password() !== "") throw "";
if (u.port() !== "80") throw "";
if (u.path() !== "/index.html") throw "";
if (u.query() !== "") throw "";
if (u.fragment() !== "") throw "";
if (u.resource() !== "/index.html") throw "";
if (u.authority() !== "[::FFFF:129.144.52.38]:80") throw "";
if (u.userinfo() !== "") throw "";
if (u.subdomain() !== "") throw "";
if (u.domain() !== "") throw "";
if (u.tld() !== "") throw "";
if (u.directory() !== "/") throw "";
if (u.filename() !== "index.html") throw "";
if (u.suffix() !== "html") throw "";
if (u.hash() !== "") throw "";
if (u.search() !== "") throw "";
if (u.host() !== "[::FFFF:129.144.52.38]:80") throw "";
if (u.hostname() !== "::FFFF:129.144.52.38") throw "";
u = new URI("http://[2010:836B:4179::836B:4179]");
if (u.protocol() !== "http") throw "";
if (u.username() !== "") throw "";
if (u.password() !== "") throw "";
if (u.port() !== "") throw "";
if (u.path() !== "/") throw "";
if (u.query() !== "") throw "";
if (u.fragment() !== "") throw "";
if (u.resource() !== "/") throw "";
if (u.authority() !== "[2010:836B:4179::836B:4179]") throw "";
if (u.userinfo() !== "") throw "";
if (u.subdomain() !== "") throw "";
if (u.domain() !== "") throw "";
if (u.tld() !== "") throw "";
if (u.directory() !== "/") throw "";
if (u.filename() !== "") throw "";
if (u.suffix() !== "") throw "";
if (u.hash() !== "") throw "";
if (u.search() !== "") throw "";
if (u.host() !== "[2010:836B:4179::836B:4179]") throw "";
if (u.hostname() !== "2010:836B:4179::836B:4179") throw "";
u = new URI("http://user:[email protected]:123/some/directory/file.html?query=string#fragment");
if (u.protocol() !== "http") throw "";
if (u.username() !== "user") throw "";
if (u.password() !== "pass") throw "";
if (u.port() !== "123") throw "";
if (u.path() !== "/some/directory/file.html") throw "";
if (u.query() !== "query=string") throw "";
if (u.fragment() !== "fragment") throw "";
if (u.resource() !== "/some/directory/file.html?query=string#fragment") throw "";
if (u.authority() !== "user:[email protected]:123") throw "";
if (u.userinfo() !== "user:pass") throw "";
if (u.subdomain() !== "") throw "";
if (u.domain() !== "xn--exmple-cua.org") throw "";
if (u.tld() !== "org") throw "";
if (u.directory() !== "/some/directory") throw "";
if (u.filename() !== "file.html") throw "";
if (u.suffix() !== "html") throw "";
if (u.hash() !== "#fragment") throw "";
if (u.search() !== "?query=string") throw "";
if (u.host() !== "xn--exmple-cua.org:123") throw "";
if (u.hostname() !== "xn--exmple-cua.org") throw "";
u = new URI("http://user:pass@exämple.org:123/some/directory/file.html?query=string#fragment");
if (u.protocol() !== "http") throw "";
if (u.username() !== "user") throw "";
if (u.password() !== "pass") throw "";
if (u.port() !== "123") throw "";
if (u.path() !== "/some/directory/file.html") throw "";
if (u.query() !== "query=string") throw "";
if (u.fragment() !== "fragment") throw "";
if (u.resource() !== "/some/directory/file.html?query=string#fragment") throw "";
if (u.authority() !== "user:pass@exämple.org:123") throw "";
if (u.userinfo() !== "user:pass") throw "";
if (u.subdomain() !== "") throw "";
if (u.domain() !== "exämple.org") throw "";
if (u.tld() !== "org") throw "";
if (u.directory() !== "/some/directory") throw "";
if (u.filename() !== "file.html") throw "";
if (u.suffix() !== "html") throw "";
if (u.hash() !== "#fragment") throw "";
if (u.search() !== "?query=string") throw "";
if (u.host() !== "exämple.org:123") throw "";
if (u.hostname() !== "exämple.org") throw "";
u = new URI("file:///foo/bar/baz.html");
if (u.protocol() !== "file") throw "";
if (u.username() !== "") throw "";
if (u.password() !== "") throw "";
if (u.port() !== "") throw "";
if (u.path() !== "/foo/bar/baz.html") throw "";
if (u.query() !== "") throw "";
if (u.fragment() !== "") throw "";
if (u.resource() !== "/foo/bar/baz.html") throw "";
if (u.authority() !== "") throw "";
if (u.userinfo() !== "") throw "";
if (u.subdomain() !== "") throw "";
if (u.domain() !== "") throw "";
if (u.tld() !== "") throw "";
if (u.directory() !== "/foo/bar") throw "";
if (u.filename() !== "baz.html") throw "";
if (u.suffix() !== "html") throw "";
if (u.hash() !== "") throw "";
if (u.search() !== "") throw "";
if (u.host() !== "") throw "";
if (u.hostname() !== "") throw "";
u = new URI("file://example.org:123/foo/bar/baz.html");
if (u.protocol() !== "file") throw "";
if (u.username() !== "") throw "";
if (u.password() !== "") throw "";
if (u.port() !== "123") throw "";
if (u.path() !== "/foo/bar/baz.html") throw "";
if (u.query() !== "") throw "";
if (u.fragment() !== "") throw "";
if (u.resource() !== "/foo/bar/baz.html") throw "";
if (u.authority() !== "example.org:123") throw "";
if (u.userinfo() !== "") throw "";
if (u.subdomain() !== "") throw "";
if (u.domain() !== "example.org") throw "";
if (u.tld() !== "org") throw "";
if (u.directory() !== "/foo/bar") throw "";
if (u.filename() !== "baz.html") throw "";
if (u.suffix() !== "html") throw "";
if (u.hash() !== "") throw "";
if (u.search() !== "") throw "";
if (u.host() !== "example.org:123") throw "";
if (u.hostname() !== "example.org") throw "";
u = new URI("file:///C:/WINDOWS/foo.txt");
if (u.protocol() !== "file") throw "";
if (u.username() !== "") throw "";
if (u.password() !== "") throw "";
if (u.port() !== "") throw "";
if (u.path() !== "/C:/WINDOWS/foo.txt") throw "";
if (u.query() !== "") throw "";
if (u.fragment() !== "") throw "";
if (u.resource() !== "/C:/WINDOWS/foo.txt") throw "";
if (u.authority() !== "") throw "";
if (u.userinfo() !== "") throw "";
if (u.subdomain() !== "") throw "";
if (u.domain() !== "") throw "";
if (u.tld() !== "") throw "";
if (u.directory() !== "/C:/WINDOWS") throw "";
if (u.filename() !== "foo.txt") throw "";
if (u.suffix() !== "txt") throw "";
if (u.hash() !== "") throw "";
if (u.search() !== "") throw "";
if (u.host() !== "") throw "";
if (u.hostname() !== "") throw "";
u = new URI("file://example.org/C:/WINDOWS/foo.txt");
if (u.protocol() !== "file") throw "";
if (u.username() !== "") throw "";
if (u.password() !== "") throw "";
if (u.port() !== "") throw "";
if (u.path() !== "/C:/WINDOWS/foo.txt") throw "";
if (u.query() !== "") throw "";
if (u.fragment() !== "") throw "";
if (u.resource() !== "/C:/WINDOWS/foo.txt") throw "";
if (u.authority() !== "example.org") throw "";
if (u.userinfo() !== "") throw "";
if (u.subdomain() !== "") throw "";
if (u.domain() !== "example.org") throw "";
if (u.tld() !== "org") throw "";
if (u.directory() !== "/C:/WINDOWS") throw "";
if (u.filename() !== "foo.txt") throw "";
if (u.suffix() !== "txt") throw "";
if (u.hash() !== "") throw "";
if (u.search() !== "") throw "";
if (u.host() !== "example.org") throw "";
if (u.hostname() !== "example.org") throw "";
u = new URI("file://localhost/C|/WINDOWS/foo.txt");
if (u.protocol() !== "file") throw "";
if (u.username() !== "") throw "";
if (u.password() !== "") throw "";
if (u.port() !== "") throw "";
if (u.path() !== "/C|/WINDOWS/foo.txt") throw "";
if (u.query() !== "") throw "";
if (u.fragment() !== "") throw "";
if (u.resource() !== "/C|/WINDOWS/foo.txt") throw "";
if (u.authority() !== "localhost") throw "";
if (u.userinfo() !== "") throw "";
if (u.subdomain() !== "") throw "";
if (u.domain() !== "localhost") throw "";
if (u.tld() !== "localhost") throw "";
if (u.directory() !== "/C|/WINDOWS") throw "";
if (u.filename() !== "foo.txt") throw "";
if (u.suffix() !== "txt") throw "";
if (u.hash() !== "") throw "";
if (u.search() !== "") throw "";
if (u.host() !== "localhost") throw "";
if (u.hostname() !== "localhost") throw "";
u = new URI("http://www.example.org/@foobar");
if (u.protocol() !== "http") throw "";
if (u.username() !== "") throw "";
if (u.password() !== "") throw "";
if (u.port() !== "") throw "";
if (u.path() !== "/@foobar") throw "";
if (u.query() !== "") throw "";
if (u.fragment() !== "") throw "";
if (u.resource() !== "/@foobar") throw "";
if (u.authority() !== "www.example.org") throw "";
if (u.userinfo() !== "") throw "";
if (u.subdomain() !== "www") throw "";
if (u.domain() !== "example.org") throw "";
if (u.tld() !== "org") throw "";
if (u.directory() !== "/") throw "";
if (u.filename() !== "@foobar") throw "";
if (u.suffix() !== "") throw "";
if (u.hash() !== "") throw "";
if (u.search() !== "") throw "";
if (u.host() !== "www.example.org") throw "";
if (u.hostname() !== "www.example.org") throw "";
u = new URI("mailto:[email protected]?subject=hello");
if (u.protocol() !== "mailto") throw "";
if (u.username() !== "") throw "";
if (u.password() !== "") throw "";
if (u.port() !== "") throw "";
if (u.path() !== "[email protected]") throw "";
if (u.query() !== "subject=hello") throw "";
if (u.fragment() !== "") throw "";
if (u.resource() !== "[email protected]?subject=hello") throw "";
if (u.authority() !== "") throw "";
if (u.userinfo() !== "") throw "";
if (u.subdomain() !== "") throw "";
if (u.domain() !== "") throw "";
if (u.tld() !== "") throw "";
if (u.directory() !== "") throw "";
if (u.filename() !== "") throw "";
if (u.suffix() !== "") throw "";
if (u.hash() !== "") throw "";
if (u.search() !== "?subject=hello") throw "";
if (u.host() !== "") throw "";
if (u.hostname() !== "") throw "";
u = new URI("magnet:?xt=urn:btih:f8c020dac7a083defda1769a1196a13facc38ef6&dn=Linux+64x+server+11.10+Pt+Pt&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80&tr=udp%3A%2F%2Ftracker.ccc.de%3A80");
if (u.protocol() !== "magnet") throw "";
if (u.username() !== "") throw "";
if (u.password() !== "") throw "";
if (u.port() !== "") throw "";
if (u.path() !== "") throw "";
if (u.query() !== "xt=urn:btih:f8c020dac7a083defda1769a1196a13facc38ef6&dn=Linux+64x+server+11.10+Pt+Pt&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80&tr=udp%3A%2F%2Ftracker.ccc.de%3A80") throw "";
if (u.fragment() !== "") throw "";
if (u.resource() !== "?xt=urn:btih:f8c020dac7a083defda1769a1196a13facc38ef6&dn=Linux+64x+server+11.10+Pt+Pt&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80&tr=udp%3A%2F%2Ftracker.ccc.de%3A80") throw "";
if (u.authority() !== "") throw "";
if (u.userinfo() !== "") throw "";
if (u.subdomain() !== "") throw "";
if (u.domain() !== "") throw "";
if (u.tld() !== "") throw "";
if (u.directory() !== "") throw "";
if (u.filename() !== "") throw "";
if (u.suffix() !== "") throw "";
if (u.hash() !== "") throw "";
if (u.search() !== "?xt=urn:btih:f8c020dac7a083defda1769a1196a13facc38ef6&dn=Linux+64x+server+11.10+Pt+Pt&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80&tr=udp%3A%2F%2Ftracker.ccc.de%3A80") throw "";
if (u.host() !== "") throw "";
if (u.hostname() !== "") throw "";
u = new URI("javascript:alert(\"hello world\");");
if (u.protocol() !== "javascript") throw "";
if (u.username() !== "") throw "";
if (u.password() !== "") throw "";
if (u.port() !== "") throw "";
if (u.path() !== "alert(\"hello world\");") throw "";
if (u.query() !== "") throw "";
if (u.fragment() !== "") throw "";
if (u.resource() !== "alert(\"hello world\");") throw "";
if (u.authority() !== "") throw "";
if (u.userinfo() !== "") throw "";
if (u.subdomain() !== "") throw "";
if (u.domain() !== "") throw "";
if (u.tld() !== "") throw "";
if (u.directory() !== "") throw "";
if (u.filename() !== "") throw "";
if (u.suffix() !== "") throw "";
if (u.hash() !== "") throw "";
if (u.search() !== "") throw "";
if (u.host() !== "") throw "";
if (u.hostname() !== "") throw "";
u = new URI("http://en.wikipedia.org/wiki/Help:IPA");
if (u.protocol() !== "http") throw "";
if (u.username() !== "") throw "";
if (u.password() !== "") throw "";
if (u.port() !== "") throw "";
if (u.path() !== "/wiki/Help:IPA") throw "";
if (u.query() !== "") throw "";
if (u.fragment() !== "") throw "";
if (u.resource() !== "/wiki/Help:IPA") throw "";
if (u.authority() !== "en.wikipedia.org") throw "";
if (u.userinfo() !== "") throw "";
if (u.subdomain() !== "en") throw "";
if (u.domain() !== "wikipedia.org") throw "";
if (u.tld() !== "org") throw "";
if (u.directory() !== "/wiki") throw "";
if (u.filename() !== "Help:IPA") throw "";
if (u.suffix() !== "") throw "";
if (u.hash() !== "") throw "";
if (u.search() !== "") throw "";
if (u.host() !== "en.wikipedia.org") throw "";
if (u.hostname() !== "en.wikipedia.org") throw "";
u = new URI("/wiki/Help:IPA");
if (u.protocol() !== "") throw "";
if (u.username() !== "") throw "";
if (u.password() !== "") throw "";
if (u.port() !== "") throw "";
if (u.path() !== "/wiki/Help:IPA") throw "";
if (u.query() !== "") throw "";
if (u.fragment() !== "") throw "";
if (u.resource() !== "/wiki/Help:IPA") throw "";
if (u.authority() !== "") throw "";
if (u.userinfo() !== "") throw "";
if (u.subdomain() !== "") throw "";
if (u.domain() !== "") throw "";
if (u.tld() !== "") throw "";
if (u.directory() !== "/wiki") throw "";
if (u.filename() !== "Help:IPA") throw "";
if (u.suffix() !== "") throw "";
if (u.hash() !== "") throw "";
if (u.search() !== "") throw "";
if (u.host() !== "") throw "";
if (u.hostname() !== "") throw "";
u = new URI("/foo/xy://bar");
if (u.protocol() !== "") throw "";
if (u.username() !== "") throw "";
if (u.password() !== "") throw "";
if (u.port() !== "") throw "";
if (u.path() !== "/foo/xy://bar") throw "";
if (u.query() !== "") throw "";
if (u.fragment() !== "") throw "";
if (u.resource() !== "/foo/xy://bar") throw "";
if (u.authority() !== "") throw "";
if (u.userinfo() !== "") throw "";
if (u.subdomain() !== "") throw "";
if (u.domain() !== "") throw "";
if (u.tld() !== "") throw "";
if (u.directory() !== "/foo/xy:/") throw "";
if (u.filename() !== "bar") throw "";
if (u.suffix() !== "") throw "";
if (u.hash() !== "") throw "";
if (u.search() !== "") throw "";
if (u.host() !== "") throw "";
if (u.hostname() !== "") throw "";
u = new URI("http://www.example.org:8080/hello:world");
if (u.protocol() !== "http") throw "";
if (u.username() !== "") throw "";
if (u.password() !== "") throw "";
if (u.port() !== "8080") throw "";
if (u.path() !== "/hello:world") throw "";
if (u.query() !== "") throw "";
if (u.fragment() !== "") throw "";
if (u.resource() !== "/hello:world") throw "";
if (u.authority() !== "www.example.org:8080") throw "";
if (u.userinfo() !== "") throw "";
if (u.subdomain() !== "www") throw "";
if (u.domain() !== "example.org") throw "";
if (u.tld() !== "org") throw "";
if (u.directory() !== "/") throw "";
if (u.filename() !== "hello:world") throw "";
if (u.suffix() !== "") throw "";
if (u.hash() !== "") throw "";
if (u.search() !== "") throw "";
if (u.host() !== "www.example.org:8080") throw "";
if (u.hostname() !== "www.example.org") throw "";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment