From 09fd3b55a61cb4288a479a1c956de4975ce1e92d Mon Sep 17 00:00:00 2001 From: Wai Ting Cheung Date: Mon, 12 Dec 2016 19:04:55 +0800 Subject: [PATCH 01/44] fix(constructor): prevent null values from blowing up - #321 --- CHANGELOG.md | 4 ++++ src/URI.js | 6 ++++++ test/test.js | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08f60e2e..3db1d07e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ The release notes tracked in this document are also made available on the [releases page](https://github.com/medialize/URI.js/releases) +### master + +* prevent `new URI(null)` from blowing up - [PR #321](https://github.com/medialize/URI.js/issues/321) + ### 1.18.4 (December 4th 2016) ### * fixing [`URI.withinString()`](http://medialize.github.io/URI.js/docs.html#static-withinString) to capture balanced parentheses - [Issue #247](https://github.com/medialize/URI.js/issues/247) diff --git a/src/URI.js b/src/URI.js index 30dcc876..398562d7 100644 --- a/src/URI.js +++ b/src/URI.js @@ -61,6 +61,12 @@ } } + if (url === null) { + if (_urlSupplied) { + throw new TypeError('null is not a valid argument for URI'); + } + } + this.href(url); // resolve to base according to http://dvcs.w3.org/hg/url/raw-file/tip/Overview.html#constructor diff --git a/test/test.js b/test/test.js index 03ecc5a0..c24316d9 100644 --- a/test/test.js +++ b/test/test.js @@ -19,6 +19,11 @@ URI(undefined); }, TypeError, 'Failing undefined input'); }); + test('URI(null)', function() { + raises(function() { + URI(null); + }, TypeError, 'Failing undefined input'); + }); test('new URI(string)', function() { var u = new URI('http://example.org/'); ok(u instanceof URI, 'instanceof URI'); From 247ef6ab2f05eeabe5f585cce6458bf9216763e3 Mon Sep 17 00:00:00 2001 From: Wai Ting Cheung Date: Mon, 16 Jan 2017 19:30:19 +0800 Subject: [PATCH 02/44] fix(filename): generalize guard for invalid filename - #324 --- src/URI.js | 2 +- test/test_jim.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/URI.js b/src/URI.js index 398562d7..8ce8606b 100644 --- a/src/URI.js +++ b/src/URI.js @@ -1571,7 +1571,7 @@ return v === undefined ? '' : this; } - if (v === undefined || v === true) { + if (typeof v !== 'string') { if (!this._parts.path || this._parts.path === '/') { return ''; } diff --git a/test/test_jim.js b/test/test_jim.js index 2be6def1..86204c29 100644 --- a/test/test_jim.js +++ b/test/test_jim.js @@ -98,6 +98,18 @@ u.filename('../name.html?query'); equal(u.filename(), 'name.html%3Fquery', 'filename() has set invalid filename'); equal(u.directory(), '/dir1', 'filename() has not altered directory properly'); + + u.filename(null); + equal(u.filename(), 'name.html%3Fquery', 'filename() has set invalid filename'); + equal(u.directory(), '/dir1', 'filename() has not altered directory properly'); + + u.filename(false); + equal(u.filename(), 'name.html%3Fquery', 'filename() has set invalid filename'); + equal(u.directory(), '/dir1', 'filename() has not altered directory properly'); + + u.filename(0); + equal(u.filename(), 'name.html%3Fquery', 'filename() has set invalid filename'); + equal(u.directory(), '/dir1', 'filename() has not altered directory properly'); }); test('addQuery', function() { var u = new URI('http://example.com/dir1/dir2/?query1=value1&query2=value2#hash'); From bff867463fcf633d300a0db0375ccb0d32aa448c Mon Sep 17 00:00:00 2001 From: Rodney Rehm Date: Tue, 17 Jan 2017 22:29:59 +0100 Subject: [PATCH 03/44] docs(joinPaths): fixing "joinPath()" -> "joinPaths()" --- docs.html | 212 +++++++++++++++++++++++++++--------------------------- 1 file changed, 106 insertions(+), 106 deletions(-) diff --git a/docs.html b/docs.html index 31d58ed5..cd955180 100644 --- a/docs.html +++ b/docs.html @@ -5,7 +5,7 @@ URI.js - API Documentation - + @@ -30,7 +30,7 @@ Fork me on GitHub

URI.js

- + - + @@ -166,25 +166,25 @@

URI.js

Static Helper Functions - +

URI.js API

- +

URI Constructor

var uri = new URI(); // same as new URI(location.href)
 // string
@@ -204,10 +204,10 @@ 

URI Constructor

// resolving right in the constructor var uri = URI("../foobar.html", "http://example.org/hello/world.html"); -// which is exactly the same as +// which is exactly the same as URI("../foobar.html").absoluteTo("http://example.org/hello/world.html"); // but specified in URL constructor
- +

The following parts can be specified in an object:

var uri = new URI({
   protocol: "http", // no trailing :
@@ -268,7 +268,7 @@ 

cloning URIs

uri2.tld("com"); uri == "http://example.org/"; uri2 == "http://example.com/";
- +

href()

get and set the entire URI

var uri = URI("http://example.com");
@@ -276,15 +276,15 @@ 

href()

uri.href("ftp://google.org"); uri.toString() === "ftp://google.org/"
- +

toString(), valueOf()

serialize the URI to string. valueOf() is an alias to toString(), as string is the base primitive.

var uri = URI("http://example.com");
 var s = uri.toString();
 typeof s === "string";
 s === "http://example.com/";
- - + +

protocol(), scheme()

.scheme() is an alias of .protocol()

var uri = new URI("http://example.org/foo/hello.html");
@@ -304,14 +304,14 @@ 

username()

uri.username(); // returns string "user" // set username uri.username("user"); // returns the URI instance for chaining
- +

password()

var uri = new URI("http://user:pass@example.org/foo/hello.html");
 // get password
 uri.password(); // returns string "pass"
 // set password
 uri.password("user"); // returns the URI instance for chaining
- +

hostname()

var uri = new URI("http://example.org/foo/hello.html");
 // get hostname
@@ -319,7 +319,7 @@ 

hostname()

// set hostname uri.hostname("example.org"); // returns the URI instance for chaining

.hostname() returns the actual hostname, whereas .host() returns the hostname including the port

- +

port()

var uri = new URI("http://example.org:8080/foo/hello.html");
 // get port
@@ -328,7 +328,7 @@ 

port()

uri.port("80"); // returns the URI instance for chaining

although the port may be considered an integer, within URI it is a string.

Throws a TypeError on illegal input

- +

host()

var uri = new URI("http://example.org:80/foo/hello.html");
 // get host
@@ -345,7 +345,7 @@ 

userinfo()

uri.userinfo(); // returns string "user:pass" // set userinfo uri.userinfo("user:pass"); // returns the URI instance for chaining
- +

authority()

Authority is comprised of username, password, hostname and port

var uri = new URI("http://user:pass@example.org:88/foo/hello.html");
@@ -384,7 +384,7 @@ 

domain()

uri.domain(true); // return string "co.uk"

.domain() will throw an error if you pass it an empty string.

Throws a TypeError on illegal input

- +

subdomain()

.subdomain() is a convenience method that returns www from the hostname www.example.org.

var uri = new URI("http://www.example.org/foo/hello.html");
@@ -393,7 +393,7 @@ 

subdomain()

// set subdomain uri.subdomain("other.subdomain"); // returns the URI instance for chaining

Throws a TypeError on illegal input

- +

tld()

.tld() is a convenience method that returns org from the hostname www.example.org.

var uri = new URI("http://example.org/foo/hello.html");
@@ -427,7 +427,7 @@ 

pathname(), path()

URI("/").path() === "/"; URI("http://example.org").path() === "/";
- +

directory()

.directory() is an convenience method for mutating the directory part of a path

var uri = new URI("http://example.org/foo/hello.html");
@@ -449,7 +449,7 @@ 

directory()

// -&t; "/" uri.href("foo").directory() // -&t; ""
- +

filename()

.filename() is an convenience method for mutating the filename part of a path

var uri = new URI("http://example.org/foo/hello.html");
@@ -465,7 +465,7 @@ 

filename()

// will decode for you uri.filename(true) === "hello world.html";

If you pass ../file.html, the directory will be changed accordingly

- +

suffix()

.suffix() is an convenience method for mutating the filename part of a path

var uri = new URI("http://example.org/foo/hello.html");
@@ -480,7 +480,7 @@ 

suffix()

uri.suffix() === "w%C3%BCrgh"; // will decode for you uri.suffix(true) === "würgh";
- +

segment()

.segment() allows convenient access to directory levels / URN segments within the path. See .segmentCoded() for an interface that transparently encodes and decodes path segments.

var uri = new URI("http://example.org/foo/hello.html");
@@ -520,8 +520,8 @@ 

segmentCoded()

// append level uri.segmentCoded("append this"); // -> http://example.org/bar/foobar.html/append%20this
- - + +
var uri = new URI("http://example.org/foo/hello.html?foo=bar&bar=baz");
 // get search
@@ -563,7 +563,7 @@ 
 // If you're dealing with PHP, you probably want the latter…
 uri.search("?foo=bar&bar=baz");
 uri.search("?foo=bar[]&bar[]=baz");
-

Note that names and values passed in an object are encoded automatically. +

Note that names and values passed in an object are encoded automatically. The object, resulting from parsing the query string, contains decoded values

Hint: If you're using jQuery, have a look at their .serialize() function.

@@ -584,7 +584,7 @@

hash(), fragment()

uri.hash("#mars"); // returns the URI instance for chaining uri.hash("mars"); // returns the URI instance for chaining // uri == "http://example.org/bar/world.xml#mars" - +

resource()

Resource is comprised of path, query and fragment

var uri = new URI("http://example.org/foo/hello.html?query=string#hash");
@@ -659,10 +659,10 @@ 

is()

uri.is("punycode") === false; uri.is("idn") === false; uri.is("ip") === false;
- - + +

Working with the query string

- +

setSearch(), setQuery()

.setQuery() is an alias of .setSearch()

var uri = new URI("?hello=world");
@@ -680,7 +680,7 @@ 

setSearch(), setQuery()

uri.setSearch("foo", ["bar", "baz"]); uri.setSearch("foo[]", ["bar", "baz"]);

Note that names and values passed in are encoded automatically.

- +

addSearch(), addQuery()

.addQuery() is an alias of .addSearch()

var uri = new URI("?hello=world");
@@ -698,7 +698,7 @@ 

addSearch(), addQuery()

uri.addSearch("foo", ["bar", "baz"]); uri.addSearch("foo[]", ["bar", "baz"]);

Note that names and values passed in are encoded automatically.

- +

removeSearch(), removeQuery()

.removeQuery() is an alias of .removeSearch()

var uri = new URI("?hello=world&hello=mars&foo=bar");
@@ -714,7 +714,7 @@ 

removeSearch(), removeQuery()

// remove multiple values uri.search("?hello=world&hello=mars&foo=bar&mine=true"); uri.removeSearch(["hello", "foo"]); -// uri == "?mine=true" +// uri == "?mine=true" // remove multiple values with value filter uri.search("?hello=world&hello=mars&foo=bar&mine=true&a=1&a=2&a=3"); @@ -775,27 +775,27 @@

hasSearch(), hasQuery()

Working with the Fragment (Hash)

- There are virtually no limits to what you might do with fragments (hash). - Every system has their own bag of tricks. + There are virtually no limits to what you might do with fragments (hash). + Every system has their own bag of tricks. As a result URI.js cannot offer any of the following tools right out of the box. The most common abuse of fragments are storing URLs or query string like data.

- +

- Usually a prefix is used to identify data with special meaning. This prefix can be pretty much what you want. - For URIs it's usually ! and for query-like data it often is ?. + Usually a prefix is used to identify data with special meaning. This prefix can be pretty much what you want. + For URIs it's usually ! and for query-like data it often is ?. But they don't have to, which is why you can define a global default: URI.fragmentPrefix = "$";

Query String Fragments

The file src/URI.fragmentQuery.js is a "plugin" that allows you to store data in hashes in the same manner the .query() functions provide.

- +
var uri = new URI("#?hello=world");
 uri.addFragment("hello", "mars"); // returns the URI instance for chaining
 // uri == "#?hello=world&hello=mars"
 
 // to change the fragment prefix on an instance level:
-uri.fragmentPrefix("!"); 
+uri.fragmentPrefix("!");
 
 // to change the fragment prefix on a global level:
 URI.fragmentPrefix = "!";
@@ -803,7 +803,7 @@

Query String Fragments

URL Fragments

The file src/URI.fragmentURI.js is a "plugin" that allows you to store URLs in hashes.

- +
var uri = URI("http://example.org/#!/foo/bar/baz.html");
 var furi = uri.fragment(true);
 
@@ -815,22 +815,22 @@ 

URL Fragments

uri.toString() === "http://example.org/#!/hello.html" // to change the fragment prefix on an instance level: -uri.fragmentPrefix("?"); +uri.fragmentPrefix("?"); // to change the fragment prefix on a global level: URI.fragmentPrefix = "?";
- +

Normalizing URLs

- +

normalize()

executes normalizeProtocol(), normalizeHostname(), normalizePort(), normalizePath(), normalizeSearch(), normalizeHash()

- +

normalizeProtocol()

var uri = new URI("hTTp://www.example.org/");
 // normalize protocol
 uri.normalizeProtocol(); // returns the URI instance for chaining
 // uri == "http://www.example.org/"
- +

normalizeHostname()

For IDN conversion punycode.js must be available (bundled in URI.js). For IPv6-best-notation conversion IPv6.js must be available (bundled in URI.js). Also lower-cases hostnames.

@@ -878,7 +878,7 @@

normalizeHash(), normalizeFragment()

// normalize hash uri.normalizeHash(); // returns the URI instance for chaining // uri == "http://example.org/bar/world.xml"
- +

Charsets / Encodings

@@ -894,10 +894,10 @@

unicode()

var uri = new URI("/%E4.html");
 uri.unicode(); // returns the URI instance for chaining
 // uri == "/%C3%A4.html"
- - + +

Formatting URLs

- +

readable()

Formats URLs to be human readable (much like your browser does nowadays).

var uri = new URI("http://foo:bar@www.xn--exmple-cua.org/"
@@ -955,10 +955,10 @@ 

absoluteTo()

u.absoluteTo('https://'); // -> "https://example.com/path"

.relativeTo() and .absoluteTo() reverse each other.

- +

Comparing URLs

- +

equals()

.equals() determines if the given URLs are the same - disregarding default ports, capitalization, dot-pathnames, query-parameter order, etc.

var a = "http://example.org/foo/bar.html"
@@ -982,52 +982,52 @@ 

equals()

// shorthand for comparing to window.location.href: URI(a).equals();
- +

Parsing URLs

- +

URI.parse(string url)

parses a string into its URI components. returns an object containing the found components

var result = URI.parse("http://example.org/foo.html");
 result === {
-  protocol: "http", 
-  username: null, 
-  password: null, 
+  protocol: "http",
+  username: null,
+  password: null,
   hostname: "example.org",
   port: null,
   path: "/foo.html",
   query: null,
   fragment: null
 };
- +

URI.parseAuthority(string url, object parts)

-

parses a string's beginning into its URI components username, password, hostname, port. +

parses a string's beginning into its URI components username, password, hostname, port. Found components are appended to the parts parameter. Remaining string is returned

var parts = {};
 var result = URI.parseAuthority("user:pass@example.org:8080/foo.html", parts);
 result === "/foo.html";
 parts === {
-  username: "user", 
-  password: "pass", 
+  username: "user",
+  password: "pass",
   hostname: "example.org",
   port: "8080"
 };
- +

URI.parseUserinfo(string url, object parts)

-

parses a string's beginning into its URI components username, password. +

parses a string's beginning into its URI components username, password. Found components are appended to the parts parameter. Remaining string is returned

var parts = {};
 var result = URI.parseUserinfo("user:pass@example.org:8080/foo.html", parts);
 result === "example.org:8080/foo.html";
 parts === {
-  username: "user", 
+  username: "user",
   password: "pass"
 };
- +

URI.parseHost(string url, object parts)

-

parses a string's beginning into its URI components hostname, port. +

parses a string's beginning into its URI components hostname, port. Found components are appended to the parts parameter. Remaining string is returned

var parts = {};
@@ -1037,7 +1037,7 @@ 

URI.parseHost(string url, object par hostname: "example.org", port: "8080" };

- +

URI.parseQuery(string querystring)

Parses the passed query string into an object. Returns object {propertyName: propertyValue}

var result = URI.parseQuery("?foo=bar&hello=world&hello=mars&bam=&yup");
@@ -1047,15 +1047,15 @@ 

URI.parseQuery(string querystring)

bam: "", yup: null };
- +

Serializing URLs

- +

URI.build(object parts)

serializes the URI components passed in parts into a URI string

var parts = {
-  protocol: "http", 
-  username: null, 
-  password: null, 
+  protocol: "http",
+  username: null,
+  password: null,
   hostname: "example.org",
   port: null,
   path: "/foo.html",
@@ -1063,12 +1063,12 @@ 

URI.build(object parts)

fragment: null }; URI.build(parts) === "http://example.org/foo.html";
- +

URI.buildAuthority(object parts)

serializes the URI components username, password, hostname, port passed in parts into a URI string

var parts = {
-  username: "user", 
-  password: "pass", 
+  username: "user",
+  password: "pass",
   hostname: "example.org",
   port: "8080"
 };
@@ -1077,11 +1077,11 @@ 

URI.buildAuthority(object parts)

URI.buildUserinfo(object parts)

serializes the URI components username, password passed in parts into a URI string

var parts = {
-  username: "user", 
+  username: "user",
   password: "pass"
 };
 URI.buildUserinfo(parts) === "user:pass@";
- +

URI.buildHost(object parts)

serializes the URI components hostname, port passed in parts into a URI string

var parts = {
@@ -1089,7 +1089,7 @@ 

URI.buildHost(object parts)

port: "8080" }; URI.buildHost(parts) === "example.org:8080";
- +

URI.buildQuery(object data, [boolean duplicateQueryParameters], [boolean escapeQuerySpace])

serializes the query string parameters

var data = {
@@ -1115,7 +1115,7 @@ 

URI.buildQuery(object data, [booleanURI.addQuery() and URI.removeQuery() URI.addQuery(data, "hello", "world"); uri.query(URI.buildQuery(data, true));

- +

As of v1.8.0 you can configure query parameter de/duplication:

// make all new URI instances allow duplicates:
 URI.duplicateQueryParameters = true; // default is false
@@ -1151,29 +1151,29 @@ 

URI.buildQuery(object data, [boolean - +

Encoding and Decoding URLs

- +

URI.encode()

Encode an URI component with strict compliance to RFC3986

URI.encode("hä lo#w*rl:d!") === "h%C3%A4%20lo%23w%2Arl%3Ad%21";
 // vs.
 encodeURIComponent("hä lo#w*rl:d!") === "h%C3%A4%20lo%23w*rl%3Ad!";
 // not how * and ! were not encoded
- +

URI.decode()

Decode an URI component

URI.decode("h%C3%A4%20lo%23w%2Arl%3Ad%21") === "hä lo#w*rl:d!";
 // note:
 URI.decode === decodeURIComponent;
- +

URI.encodeReserved()

Encode an URI component whilst preserving reserved characters

URI.encodeReserved("ä:/?#[]@!$&'()*+,;=") === "%C3%A4:/?#[]@!$&'()*+,;=";
 // vs.
-URI.encode("ä:/?#[]@!$&'()*+,;=") === 
+URI.encode("ä:/?#[]@!$&'()*+,;=") ===
   "%C3%A4%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D";
- +

URI.encodeQuery()

Encode a query string component. Works like encode(), except it handles %20 as + (space) if URI.escapeQuerySpace = true;.

URI.escapeQuerySpace = true; // default
@@ -1184,7 +1184,7 @@ 

URI.encodeQuery()

// vs. URI.encode(" ") === "%20";
- +

URI.decodeQuery()

Decode a query string component. Works like decode(), except it handles + as %20 (space) if URI.escapeQuerySpace = true;.

URI.escapeQuerySpace = true; // default
@@ -1195,8 +1195,8 @@ 

URI.decodeQuery()

// vs. URI.decode("+") === "+";
- - + +

Static Helper Functions

URI.noConflict()

@@ -1210,7 +1210,7 @@

URI.noConflict()

// restore all objects and return them as a map {URI: ..., IPv6: ..., ....} URI.noConflict(true);
- +

URI.addQuery()

adds data to a map

var data = {};
@@ -1223,7 +1223,7 @@ 

URI.addQuery()

URI.addQuery(data, {foo: "bar", goodbye : ["world", "mars"]}); data === {hello: ["mars", "world"], foo: "bar", goodbye : ["world", "mars"]};
- +

URI.removeQuery()

removes data from a map

var data === {hello: ["mars", "world"], foo: "bar", goodbye : ["world", "mars"]};
@@ -1260,8 +1260,8 @@ 

URI.commonPath()

URI.commonPath("/foo", "bar"); // returns ""
-

URI.joinPath()

-

URI.joinPath() composes a path from directory tokens.

+

URI.joinPaths()

+

URI.joinPaths() composes a path from directory tokens.

URI.joinPaths('/a/b', '/c', 'd', '/e');
 // returns URI("/a/b/c/d/e")
 
@@ -1303,7 +1303,7 @@ 

URI.withinString()

*/ // a proper replacement could look like the following: -var escapeHtml = function(string) { +var escapeHtml = function(string) { return string .replace(/&/g, "&amp;") .replace(/</g, "&lt;") @@ -1313,7 +1313,7 @@

URI.withinString()

var result = URI.withinString(source, function(url) { var uri = new URI(url); uri.normalize(); - return "<a href="" + escapeHtml(uri) + "">" + return "<a href="" + escapeHtml(uri) + "">" + escapeHtml(uri.readable()) + "</a>"; });
@@ -1368,23 +1368,23 @@

URI.withinString()

/* result is: That <code>example.com/</code> is just a domain */
- +

URI.iso8859()

URI.iso8859() tells URI.js to use the older escape/unescape methods, for backwards compatibility with non-unicode platforms.

URI.iso8859();
 
 var uri = new URI("http://example.org/foo/æ.html");
 // http://example.org/foo/%E6.html
- +

URI.unicode()

URI.unicode() restores the default unicode-encoded URLs.

URI.unicode();
 
 var uri = new URI("http://example.org/foo/æ.html");
 // http://example.org/foo/%C3%A6.html
- +

URI.expand()

-

URI.expand() is a convenience wrapper for URITemplate. +

URI.expand() is a convenience wrapper for URITemplate. While URITemplate#expand returns a string, URI.expand() returns an URI instance.

URI.expand("/foo/{var}/{iable}", {
   "var": "bar",
@@ -1393,7 +1393,7 @@ 

URI.expand()

// returns URI("/foo/bar/hello%20world.html")
- +
From c72ffca0dce50fec31c037073173eb21602dbf57 Mon Sep 17 00:00:00 2001 From: Rodney Rehm Date: Mon, 30 Jan 2017 00:26:31 +0100 Subject: [PATCH 04/44] fix(withinString): properly handle contained balanced parens - closes #325 --- CHANGELOG.md | 1 + src/URI.js | 2 +- test/test.js | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3db1d07e..23590fe3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ The release notes tracked in this document are also made available on the [relea ### master * prevent `new URI(null)` from blowing up - [PR #321](https://github.com/medialize/URI.js/issues/321) +* fixing [`URI.withinString()`](http://medialize.github.io/URI.js/docs.html#static-withinString) to properly handle fully contained parentheses - [Issue #325](https://github.com/medialize/URI.js/issues/325) ### 1.18.4 (December 4th 2016) ### diff --git a/src/URI.js b/src/URI.js index 8ce8606b..61fb3325 100644 --- a/src/URI.js +++ b/src/URI.js @@ -984,7 +984,7 @@ } if (parensEnd > -1) { - slice = slice.slice(0, parensEnd) + slice.slice(parensEnd + 1).replace(_trim, ''); + slice = slice.slice(0, parensEnd) + slice.slice(parensEnd).replace(_trim, ''); } else { slice = slice.replace(_trim, ''); } diff --git a/test/test.js b/test/test.js index c24316d9..da77e458 100644 --- a/test/test.js +++ b/test/test.js @@ -1585,14 +1585,14 @@ + 'http://exämple.org/foo.html?baz=la#bumm is an IDN URL,\n' + 'http://123.123.123.123/foo.html is IPv4 and http://fe80:0000:0000:0000:0204:61ff:fe9d:f156/foobar.html is IPv6.\n' + 'links can also be in parens (http://example.org) or quotes »http://example.org«, ' - + 'yet https://example.com/with_(balanced_parentheses) contains the closing parens, but ' + + 'yet https://example.com/with_(balanced_parentheses) and https://example.com/with_(balanced_parentheses).txt contain the closing parens, but ' + 'https://example.com/with_unbalanced_parentheses) does not.'; var expected = 'Hello www.example.com,\n' + 'http://google.com is a search engine, like http://www.bing.com\n' + 'http://exämple.org/foo.html?baz=la#bumm is an IDN URL,\n' + 'http://123.123.123.123/foo.html is IPv4 and http://fe80:0000:0000:0000:0204:61ff:fe9d:f156/foobar.html is IPv6.\n' + 'links can also be in parens (http://example.org) or quotes »http://example.org«, ' - + 'yet https://example.com/with_(balanced_parentheses) contains the closing parens, but ' + + 'yet https://example.com/with_(balanced_parentheses) and https://example.com/with_(balanced_parentheses).txt contain the closing parens, but ' + 'https://example.com/with_unbalanced_parentheses) does not.'; /*jshint laxbreak: false */ var result = URI.withinString(source, function(url) { From f86e6e1f31866c4a27324e7f7875a733bb105b77 Mon Sep 17 00:00:00 2001 From: Rodney Rehm Date: Mon, 30 Jan 2017 10:53:39 +0100 Subject: [PATCH 05/44] chore(build): bumping to version 1.18.5 --- CHANGELOG.md | 2 +- bower.json | 2 +- build.js | 2 +- package.json | 2 +- src/IPv6.js | 2 +- src/SecondLevelDomains.js | 2 +- src/URI.js | 4 ++-- src/URITemplate.js | 2 +- src/jquery.URI.js | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23590fe3..00a89dcf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ The release notes tracked in this document are also made available on the [releases page](https://github.com/medialize/URI.js/releases) -### master +### 1.18.5 (January 30th 2017) ### * prevent `new URI(null)` from blowing up - [PR #321](https://github.com/medialize/URI.js/issues/321) * fixing [`URI.withinString()`](http://medialize.github.io/URI.js/docs.html#static-withinString) to properly handle fully contained parentheses - [Issue #325](https://github.com/medialize/URI.js/issues/325) diff --git a/bower.json b/bower.json index 6fbcff2e..ad672486 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "urijs", - "version": "1.18.4", + "version": "1.18.5", "main": "src/URI.js", "ignore": [ ".*", diff --git a/build.js b/build.js index 0808d985..950940f8 100644 --- a/build.js +++ b/build.js @@ -29,7 +29,7 @@ function build(files) { output_format: "text", output_info: "compiled_code" }, function(data) { - var code = "/*! URI.js v1.18.4 http://medialize.github.io/URI.js/ */\n/* build contains: " + files.join(', ') + " */\n" + data; + var code = "/*! URI.js v1.18.5 http://medialize.github.io/URI.js/ */\n/* build contains: " + files.join(', ') + " */\n" + data; $progress.hide(); $out.val(code).parent().show(); $out.prev().find('a').remove(); diff --git a/package.json b/package.json index c94e3969..88080e96 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "urijs", - "version": "1.18.4", + "version": "1.18.5", "title": "URI.js - Mutating URLs", "author": { "name": "Rodney Rehm", diff --git a/src/IPv6.js b/src/IPv6.js index 915f76fa..98b47a3f 100644 --- a/src/IPv6.js +++ b/src/IPv6.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * IPv6 Support * - * Version: 1.18.4 + * Version: 1.18.5 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/SecondLevelDomains.js b/src/SecondLevelDomains.js index c42d1aa6..69fa76b5 100644 --- a/src/SecondLevelDomains.js +++ b/src/SecondLevelDomains.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * Second Level Domain (SLD) Support * - * Version: 1.18.4 + * Version: 1.18.5 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/URI.js b/src/URI.js index 61fb3325..9d691f80 100644 --- a/src/URI.js +++ b/src/URI.js @@ -1,7 +1,7 @@ /*! * URI.js - Mutating URLs * - * Version: 1.18.4 + * Version: 1.18.5 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ @@ -77,7 +77,7 @@ return this; } - URI.version = '1.18.4'; + URI.version = '1.18.5'; var p = URI.prototype; var hasOwn = Object.prototype.hasOwnProperty; diff --git a/src/URITemplate.js b/src/URITemplate.js index fddcab70..0280fa73 100644 --- a/src/URITemplate.js +++ b/src/URITemplate.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * URI Template Support - http://tools.ietf.org/html/rfc6570 * - * Version: 1.18.4 + * Version: 1.18.5 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/jquery.URI.js b/src/jquery.URI.js index 0dd4a397..23b7a511 100644 --- a/src/jquery.URI.js +++ b/src/jquery.URI.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * jQuery Plugin * - * Version: 1.18.4 + * Version: 1.18.5 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/jquery-uri-plugin.html From dfc50a0a10cffa20ed4afc1319c3c0e904b3a020 Mon Sep 17 00:00:00 2001 From: Rodney Rehm Date: Mon, 30 Jan 2017 11:01:54 +0100 Subject: [PATCH 06/44] chore(dist): updating distributables to version 1.18.5 --- src/URI.min.js | 14 +++++++------- src/jquery.URI.min.js | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/URI.min.js b/src/URI.min.js index dfdbc3be..3c01933f 100644 --- a/src/URI.min.js +++ b/src/URI.min.js @@ -1,4 +1,4 @@ -/*! URI.js v1.18.4 http://medialize.github.io/URI.js/ */ +/*! URI.js v1.18.5 http://medialize.github.io/URI.js/ */ /* build contains: IPv6.js, punycode.js, SecondLevelDomains.js, URI.js, URITemplate.js */ (function(f,l){"object"===typeof module&&module.exports?module.exports=l():"function"===typeof define&&define.amd?define(l):f.IPv6=l(f)})(this,function(f){var l=f&&f.IPv6;return{best:function(g){g=g.toLowerCase().split(":");var k=g.length,b=8;""===g[0]&&""===g[1]&&""===g[2]?(g.shift(),g.shift()):""===g[0]&&""===g[1]?g.shift():""===g[k-1]&&""===g[k-2]&&g.pop();k=g.length;-1!==g[k-1].indexOf(".")&&(b=7);var m;for(m=0;mf;f++)if("0"===k[0]&&1f&&(k=h,f=l)):"0"===g[m]&&(q=!0,h=m,l=1);l>f&&(k=h,f=l);1=k||k>=b-1)return!1;var l=g.list[f.slice(b+1)];return l?0<=l.indexOf(" "+f.slice(k+1,b)+" "):!1},is:function(f){var b=f.lastIndexOf(".");if(0>=b||b>=f.length-1||0<=f.lastIndexOf(".",b-1))return!1;var k=g.list[f.slice(b+1)];return k?0<=k.indexOf(" "+f.slice(0,b)+" "):!1},get:function(f){var b=f.lastIndexOf(".");if(0>=b||b>=f.length-1)return null;var k=f.lastIndexOf(".",b-1);if(0>=k||k>=b-1)return null;var l=g.list[f.slice(b+1)];return!l||0>l.indexOf(" "+f.slice(k+ 1,b)+" ")?null:f.slice(k+1)},noConflict:function(){f.SecondLevelDomains===this&&(f.SecondLevelDomains=l);return this}};return g}); (function(f,l){"object"===typeof module&&module.exports?module.exports=l(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"===typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],l):f.URI=l(f.punycode,f.IPv6,f.SecondLevelDomains,f)})(this,function(f,l,g,k){function b(a,c){var d=1<=arguments.length,n=2<=arguments.length;if(!(this instanceof b))return d?n?new b(a,c):new b(a):new b;if(void 0===a){if(d)throw new TypeError("undefined is not a valid argument for URI"); -a="undefined"!==typeof location?location.href+"":""}this.href(a);return void 0!==c?this.absoluteTo(c):this}function m(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function z(a){return void 0===a?"Undefined":String(Object.prototype.toString.call(a)).slice(8,-1)}function v(a){return"Array"===z(a)}function h(a,c){var d={},b,t;if("RegExp"===z(c))d=null;else if(v(c))for(b=0,t=c.length;b]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u2018\u2019]))/ig;b.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u201e\u2018\u2019]+$/,parens:/(\([^\)]*\)|\[[^\]]*\]|\{[^}]*\}|<[^>]*>)/g};b.defaultPorts={http:"80",https:"443",ftp:"21", gopher:"70",ws:"80",wss:"443"};b.invalid_hostname_characters=/[^a-zA-Z0-9\.-]/;b.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src",audio:"src",video:"src"};b.getDomAttribute=function(a){if(a&&a.nodeName){var c=a.nodeName.toLowerCase();if("input"!==c||"image"===a.type)return b.domAttributes[c]}};b.encode=x;b.decode=decodeURIComponent;b.iso8859=function(){b.encode=escape;b.decode= unescape};b.unicode=function(){b.encode=x;b.decode=decodeURIComponent};b.characters={pathname:{encode:{expression:/%(24|26|2B|2C|3B|3D|3A|40)/ig,map:{"%24":"$","%26":"&","%2B":"+","%2C":",","%3B":";","%3D":"=","%3A":":","%40":"@"}},decode:{expression:/[\/\?#]/g,map:{"/":"%2F","?":"%3F","#":"%23"}}},reserved:{encode:{expression:/%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/ig,map:{"%3A":":","%2F":"/","%3F":"?","%23":"#","%5B":"[","%5D":"]","%40":"@","%21":"!","%24":"$","%26":"&","%27":"'", @@ -44,7 +44,7 @@ function(a,c,d){var n;if(v(c))for(d=0,n=c.length;db)return a.charAt(0)===c.charAt(0)&&"/"===a.charAt(0)?"/":"";if("/"!==a.charAt(b)||"/"!==c.charAt(b))b=a.substring(0,b).lastIndexOf("/");return a.substring(0,b+1)};b.withinString=function(a,c,d){d||(d={}); -var e=d.start||b.findUri.start,f=d.end||b.findUri.end,h=d.trim||b.findUri.trim,g=d.parens||b.findUri.parens,q=/[a-z0-9-]=["']?$/i;for(e.lastIndex=0;;){var k=e.exec(a);if(!k)break;k=k.index;if(d.ignoreHtml){var l=a.slice(Math.max(k-3,0),k);if(l&&q.test(l))continue}for(var p=k+a.slice(k).search(f),l=a.slice(k,p),p=-1;;){var m=g.exec(l);if(!m)break;p=Math.max(p,m.index+m[0].length)}l=-1a&&(a=Math.max(e.length+a,0));if(void 0===c)return void 0===a?e:e[a];if(null===a||void 0===e[a])if(v(c)){e=[];a=0;for(var h=c.length;a Date: Fri, 10 Feb 2017 06:47:14 -0500 Subject: [PATCH 07/44] fix(templates): Allow single quote characters in literals (#326) Single quotes are valid in uris, so we do not want to break users of this library who may have single quotes in their templates. --- src/URITemplate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/URITemplate.js b/src/URITemplate.js index 0280fa73..5c240c2f 100644 --- a/src/URITemplate.js +++ b/src/URITemplate.js @@ -137,7 +137,7 @@ // pattern to verify variable name integrity URITemplate.VARIABLE_NAME_PATTERN = /[^a-zA-Z0-9%_.]/; // pattern to verify literal integrity - URITemplate.LITERAL_PATTERN = /[<>{}'"`^| \\]/; + URITemplate.LITERAL_PATTERN = /[<>{}"`^| \\]/; // expand parsed expression (expression, not template!) URITemplate.expand = function(expression, data) { From 6024e87c1f65e50304ca52a80842ca1d1dbb0638 Mon Sep 17 00:00:00 2001 From: Rodney Rehm Date: Fri, 10 Feb 2017 12:52:03 +0100 Subject: [PATCH 08/44] chore(build): bumping to version 1.18.6 --- CHANGELOG.md | 4 ++++ bower.json | 2 +- build.js | 2 +- package.json | 2 +- src/IPv6.js | 2 +- src/SecondLevelDomains.js | 2 +- src/URI.js | 4 ++-- src/URITemplate.js | 2 +- src/jquery.URI.js | 2 +- 9 files changed, 13 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00a89dcf..072b1991 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ The release notes tracked in this document are also made available on the [releases page](https://github.com/medialize/URI.js/releases) +### 1.18.6 (February 10th 2017) ### + +* fixing [`URITemplate()`](http://medialize.github.io/URI.js/uri-template.html) to allow `'` (single quotes) in literals - [PR #326](https://github.com/medialize/URI.js/pull/326) + ### 1.18.5 (January 30th 2017) ### * prevent `new URI(null)` from blowing up - [PR #321](https://github.com/medialize/URI.js/issues/321) diff --git a/bower.json b/bower.json index ad672486..41f12d7b 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "urijs", - "version": "1.18.5", + "version": "1.18.6", "main": "src/URI.js", "ignore": [ ".*", diff --git a/build.js b/build.js index 950940f8..0dca427f 100644 --- a/build.js +++ b/build.js @@ -29,7 +29,7 @@ function build(files) { output_format: "text", output_info: "compiled_code" }, function(data) { - var code = "/*! URI.js v1.18.5 http://medialize.github.io/URI.js/ */\n/* build contains: " + files.join(', ') + " */\n" + data; + var code = "/*! URI.js v1.18.6 http://medialize.github.io/URI.js/ */\n/* build contains: " + files.join(', ') + " */\n" + data; $progress.hide(); $out.val(code).parent().show(); $out.prev().find('a').remove(); diff --git a/package.json b/package.json index 88080e96..cb795fe8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "urijs", - "version": "1.18.5", + "version": "1.18.6", "title": "URI.js - Mutating URLs", "author": { "name": "Rodney Rehm", diff --git a/src/IPv6.js b/src/IPv6.js index 98b47a3f..ade802e1 100644 --- a/src/IPv6.js +++ b/src/IPv6.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * IPv6 Support * - * Version: 1.18.5 + * Version: 1.18.6 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/SecondLevelDomains.js b/src/SecondLevelDomains.js index 69fa76b5..ac5b9b24 100644 --- a/src/SecondLevelDomains.js +++ b/src/SecondLevelDomains.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * Second Level Domain (SLD) Support * - * Version: 1.18.5 + * Version: 1.18.6 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/URI.js b/src/URI.js index 9d691f80..b7c9df89 100644 --- a/src/URI.js +++ b/src/URI.js @@ -1,7 +1,7 @@ /*! * URI.js - Mutating URLs * - * Version: 1.18.5 + * Version: 1.18.6 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ @@ -77,7 +77,7 @@ return this; } - URI.version = '1.18.5'; + URI.version = '1.18.6'; var p = URI.prototype; var hasOwn = Object.prototype.hasOwnProperty; diff --git a/src/URITemplate.js b/src/URITemplate.js index 5c240c2f..14288f86 100644 --- a/src/URITemplate.js +++ b/src/URITemplate.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * URI Template Support - http://tools.ietf.org/html/rfc6570 * - * Version: 1.18.5 + * Version: 1.18.6 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/jquery.URI.js b/src/jquery.URI.js index 23b7a511..8d81b7ef 100644 --- a/src/jquery.URI.js +++ b/src/jquery.URI.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * jQuery Plugin * - * Version: 1.18.5 + * Version: 1.18.6 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/jquery-uri-plugin.html From f14ed33e4b4704f323db4322fe658c757edca9a3 Mon Sep 17 00:00:00 2001 From: Rodney Rehm Date: Fri, 10 Feb 2017 12:56:24 +0100 Subject: [PATCH 09/44] chore(dist): updating distributables to version 1.18.6 --- src/URI.min.js | 6 +++--- src/jquery.URI.min.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/URI.min.js b/src/URI.min.js index 3c01933f..106f5c36 100644 --- a/src/URI.min.js +++ b/src/URI.min.js @@ -1,4 +1,4 @@ -/*! URI.js v1.18.5 http://medialize.github.io/URI.js/ */ +/*! URI.js v1.18.6 http://medialize.github.io/URI.js/ */ /* build contains: IPv6.js, punycode.js, SecondLevelDomains.js, URI.js, URITemplate.js */ (function(f,l){"object"===typeof module&&module.exports?module.exports=l():"function"===typeof define&&define.amd?define(l):f.IPv6=l(f)})(this,function(f){var l=f&&f.IPv6;return{best:function(g){g=g.toLowerCase().split(":");var k=g.length,b=8;""===g[0]&&""===g[1]&&""===g[2]?(g.shift(),g.shift()):""===g[0]&&""===g[1]?g.shift():""===g[k-1]&&""===g[k-2]&&g.pop();k=g.length;-1!==g[k-1].indexOf(".")&&(b=7);var m;for(m=0;mf;f++)if("0"===k[0]&&1f&&(k=h,f=l)):"0"===g[m]&&(q=!0,h=m,l=1);l>f&&(k=h,f=l);1=k||k>=b-1)return!1;var l=g.list[f.slice(b+1)] (function(f,l){"object"===typeof module&&module.exports?module.exports=l(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"===typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],l):f.URI=l(f.punycode,f.IPv6,f.SecondLevelDomains,f)})(this,function(f,l,g,k){function b(a,c){var d=1<=arguments.length,n=2<=arguments.length;if(!(this instanceof b))return d?n?new b(a,c):new b(a):new b;if(void 0===a){if(d)throw new TypeError("undefined is not a valid argument for URI"); a="undefined"!==typeof location?location.href+"":""}if(null===a&&d)throw new TypeError("null is not a valid argument for URI");this.href(a);return void 0!==c?this.absoluteTo(c):this}function m(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function z(a){return void 0===a?"Undefined":String(Object.prototype.toString.call(a)).slice(8,-1)}function v(a){return"Array"===z(a)}function h(a,c){var d={},b,t;if("RegExp"===z(c))d=null;else if(v(c))for(b=0,t=c.length;b]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u2018\u2019]))/ig;b.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u201e\u2018\u2019]+$/,parens:/(\([^\)]*\)|\[[^\]]*\]|\{[^}]*\}|<[^>]*>)/g};b.defaultPorts={http:"80",https:"443",ftp:"21", gopher:"70",ws:"80",wss:"443"};b.invalid_hostname_characters=/[^a-zA-Z0-9\.-]/;b.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src",audio:"src",video:"src"};b.getDomAttribute=function(a){if(a&&a.nodeName){var c=a.nodeName.toLowerCase();if("input"!==c||"image"===a.type)return b.domAttributes[c]}};b.encode=x;b.decode=decodeURIComponent;b.iso8859=function(){b.encode=escape;b.decode= @@ -80,7 +80,7 @@ e=e.path.substring(f.length).replace(/[^\/]*$/,"").replace(/.*?\//g,"../");d.pat e[h])return!1}else if(!A(c[h],e[h]))return!1;a[h]=!0}for(h in e)if(p.call(e,h)&&!a[h])return!1;return!0};e.duplicateQueryParameters=function(a){this._parts.duplicateQueryParameters=!!a;return this};e.escapeQuerySpace=function(a){this._parts.escapeQuerySpace=!!a;return this};return b}); (function(f,l){"object"===typeof module&&module.exports?module.exports=l(require("./URI")):"function"===typeof define&&define.amd?define(["./URI"],l):f.URITemplate=l(f.URI,f)})(this,function(f,l){function g(b){if(g._cache[b])return g._cache[b];if(!(this instanceof g))return new g(b);this.expression=b;g._cache[b]=this;return this}function k(b){this.data=b;this.cache={}}var b=l&&l.URITemplate,m=Object.prototype.hasOwnProperty,z=g.prototype,v={"":{prefix:"",separator:",",named:!1,empty_name_separator:!1, encode:"encode"},"+":{prefix:"",separator:",",named:!1,empty_name_separator:!1,encode:"encodeReserved"},"#":{prefix:"#",separator:",",named:!1,empty_name_separator:!1,encode:"encodeReserved"},".":{prefix:".",separator:".",named:!1,empty_name_separator:!1,encode:"encode"},"/":{prefix:"/",separator:"/",named:!1,empty_name_separator:!1,encode:"encode"},";":{prefix:";",separator:";",named:!0,empty_name_separator:!1,encode:"encode"},"?":{prefix:"?",separator:"&",named:!0,empty_name_separator:!0,encode:"encode"}, -"&":{prefix:"&",separator:"&",named:!0,empty_name_separator:!0,encode:"encode"}};g._cache={};g.EXPRESSION_PATTERN=/\{([^a-zA-Z0-9%_]?)([^\}]+)(\}|$)/g;g.VARIABLE_PATTERN=/^([^*:.](?:\.?[^*:.])*)((\*)|:(\d+))?$/;g.VARIABLE_NAME_PATTERN=/[^a-zA-Z0-9%_.]/;g.LITERAL_PATTERN=/[<>{}'"`^| \\]/;g.expand=function(b,f){var h=v[b.operator],k=h.named?"Named":"Unnamed",l=b.variables,q=[],m,y,u;for(u=0;y=l[u];u++)if(m=f.get(y.name),m.val.length){if(1{}"`^| \\]/;g.expand=function(b,f){var h=v[b.operator],k=h.named?"Named":"Unnamed",l=b.variables,q=[],m,y,u;for(u=0;y=l[u];u++)if(m=f.get(y.name),m.val.length){if(1 Date: Mon, 13 Feb 2017 18:37:15 +0100 Subject: [PATCH 10/44] fix(withinString): ignore "www." and "http://." - closes #327 --- src/URI.js | 6 ++++++ test/test.js | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/URI.js b/src/URI.js index b7c9df89..04b364a6 100644 --- a/src/URI.js +++ b/src/URI.js @@ -989,6 +989,12 @@ slice = slice.replace(_trim, ''); } + if (slice.length <= match[0].length) { + // the extract only contains the starting marker of a URI, + // e.g. "www" or "http://" + continue; + } + if (options.ignore && options.ignore.test(slice)) { continue; } diff --git a/test/test.js b/test/test.js index da77e458..8745d608 100644 --- a/test/test.js +++ b/test/test.js @@ -1586,14 +1586,16 @@ + 'http://123.123.123.123/foo.html is IPv4 and http://fe80:0000:0000:0000:0204:61ff:fe9d:f156/foobar.html is IPv6.\n' + 'links can also be in parens (http://example.org) or quotes »http://example.org«, ' + 'yet https://example.com/with_(balanced_parentheses) and https://example.com/with_(balanced_parentheses).txt contain the closing parens, but ' - + 'https://example.com/with_unbalanced_parentheses) does not.'; + + 'https://example.com/with_unbalanced_parentheses) does not.\n' + + 'Note that www. is not a URL and neither is http://.'; var expected = 'Hello www.example.com,\n' + 'http://google.com is a search engine, like http://www.bing.com\n' + 'http://exämple.org/foo.html?baz=la#bumm is an IDN URL,\n' + 'http://123.123.123.123/foo.html is IPv4 and http://fe80:0000:0000:0000:0204:61ff:fe9d:f156/foobar.html is IPv6.\n' + 'links can also be in parens (http://example.org) or quotes »http://example.org«, ' + 'yet https://example.com/with_(balanced_parentheses) and https://example.com/with_(balanced_parentheses).txt contain the closing parens, but ' - + 'https://example.com/with_unbalanced_parentheses) does not.'; + + 'https://example.com/with_unbalanced_parentheses) does not.\n' + + 'Note that www. is not a URL and neither is http://.'; /*jshint laxbreak: false */ var result = URI.withinString(source, function(url) { return '' + url + ''; From e4f7143d3ae83d302daef89c8974ce32f7881691 Mon Sep 17 00:00:00 2001 From: Rodney Rehm Date: Mon, 13 Feb 2017 18:39:15 +0100 Subject: [PATCH 11/44] chore(build): bumping to version 1.18.7 --- CHANGELOG.md | 4 ++++ bower.json | 2 +- build.js | 2 +- package.json | 2 +- src/IPv6.js | 2 +- src/SecondLevelDomains.js | 2 +- src/URI.js | 4 ++-- src/URITemplate.js | 2 +- src/jquery.URI.js | 2 +- 9 files changed, 13 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 072b1991..f1ce62a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ The release notes tracked in this document are also made available on the [releases page](https://github.com/medialize/URI.js/releases) +### 1.18.7 (February 13th 2017) ### + +* fixing [`URI.withinString()`](http://medialize.github.io/URI.js/docs.html#static-withinString) to ignore `www.` and `http://.` - [Issue #327](https://github.com/medialize/URI.js/issues/327) + ### 1.18.6 (February 10th 2017) ### * fixing [`URITemplate()`](http://medialize.github.io/URI.js/uri-template.html) to allow `'` (single quotes) in literals - [PR #326](https://github.com/medialize/URI.js/pull/326) diff --git a/bower.json b/bower.json index 41f12d7b..c9fa14e9 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "urijs", - "version": "1.18.6", + "version": "1.18.7", "main": "src/URI.js", "ignore": [ ".*", diff --git a/build.js b/build.js index 0dca427f..26b75e09 100644 --- a/build.js +++ b/build.js @@ -29,7 +29,7 @@ function build(files) { output_format: "text", output_info: "compiled_code" }, function(data) { - var code = "/*! URI.js v1.18.6 http://medialize.github.io/URI.js/ */\n/* build contains: " + files.join(', ') + " */\n" + data; + var code = "/*! URI.js v1.18.7 http://medialize.github.io/URI.js/ */\n/* build contains: " + files.join(', ') + " */\n" + data; $progress.hide(); $out.val(code).parent().show(); $out.prev().find('a').remove(); diff --git a/package.json b/package.json index cb795fe8..7756ca43 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "urijs", - "version": "1.18.6", + "version": "1.18.7", "title": "URI.js - Mutating URLs", "author": { "name": "Rodney Rehm", diff --git a/src/IPv6.js b/src/IPv6.js index ade802e1..145e5176 100644 --- a/src/IPv6.js +++ b/src/IPv6.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * IPv6 Support * - * Version: 1.18.6 + * Version: 1.18.7 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/SecondLevelDomains.js b/src/SecondLevelDomains.js index ac5b9b24..3139414a 100644 --- a/src/SecondLevelDomains.js +++ b/src/SecondLevelDomains.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * Second Level Domain (SLD) Support * - * Version: 1.18.6 + * Version: 1.18.7 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/URI.js b/src/URI.js index 04b364a6..0f023981 100644 --- a/src/URI.js +++ b/src/URI.js @@ -1,7 +1,7 @@ /*! * URI.js - Mutating URLs * - * Version: 1.18.6 + * Version: 1.18.7 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ @@ -77,7 +77,7 @@ return this; } - URI.version = '1.18.6'; + URI.version = '1.18.7'; var p = URI.prototype; var hasOwn = Object.prototype.hasOwnProperty; diff --git a/src/URITemplate.js b/src/URITemplate.js index 14288f86..5730a27b 100644 --- a/src/URITemplate.js +++ b/src/URITemplate.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * URI Template Support - http://tools.ietf.org/html/rfc6570 * - * Version: 1.18.6 + * Version: 1.18.7 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/jquery.URI.js b/src/jquery.URI.js index 8d81b7ef..b9a31e70 100644 --- a/src/jquery.URI.js +++ b/src/jquery.URI.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * jQuery Plugin * - * Version: 1.18.6 + * Version: 1.18.7 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/jquery-uri-plugin.html From 039629172caa4fd1a75665650eac6a8d3cafbf7e Mon Sep 17 00:00:00 2001 From: Rodney Rehm Date: Mon, 13 Feb 2017 18:41:58 +0100 Subject: [PATCH 12/44] chore(dist): updating distributables to version 1.18.7 --- src/URI.min.js | 82 +++++++++++++++++++++---------------------- src/jquery.URI.min.js | 2 +- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/URI.min.js b/src/URI.min.js index 106f5c36..00c48fc1 100644 --- a/src/URI.min.js +++ b/src/URI.min.js @@ -1,14 +1,14 @@ -/*! URI.js v1.18.6 http://medialize.github.io/URI.js/ */ +/*! URI.js v1.18.7 http://medialize.github.io/URI.js/ */ /* build contains: IPv6.js, punycode.js, SecondLevelDomains.js, URI.js, URITemplate.js */ -(function(f,l){"object"===typeof module&&module.exports?module.exports=l():"function"===typeof define&&define.amd?define(l):f.IPv6=l(f)})(this,function(f){var l=f&&f.IPv6;return{best:function(g){g=g.toLowerCase().split(":");var k=g.length,b=8;""===g[0]&&""===g[1]&&""===g[2]?(g.shift(),g.shift()):""===g[0]&&""===g[1]?g.shift():""===g[k-1]&&""===g[k-2]&&g.pop();k=g.length;-1!==g[k-1].indexOf(".")&&(b=7);var m;for(m=0;mf;f++)if("0"===k[0]&&1f&&(k=h,f=l)):"0"===g[m]&&(q=!0,h=m,l=1);l>f&&(k=h,f=l);1=f&&h>>10&1023|55296),b=56320|b&1023);return e+=r(b)}).join("")}function z(b,e){return b+22+75*(26>b)-((0!=e)<<5)}function v(b,e,h){var g=0;b=h?p(b/700):b>>1;for(b+=p(b/e);455d&&(d=0);for(n=0;n=h&&l("invalid-input");w=b.charCodeAt(d++); -w=10>w-48?w-22:26>w-65?w-65:26>w-97?w-97:36;(36<=w||w>p((2147483647-f)/g))&&l("overflow");f+=w*g;k=t<=c?1:t>=c+26?26:t-c;if(wp(2147483647/w)&&l("overflow");g*=w}g=e.length+1;c=v(f-n,g,0==n);p(f/g)>2147483647-a&&l("overflow");a+=p(f/g);f%=g;e.splice(f++,0,a)}return m(e)}function q(e){var h,g,f,k,a,c,d,n,t,w=[],q,m,A;e=b(e);q=e.length;h=128;g=0;a=72;for(c=0;ct&&w.push(r(t));for((f=k=w.length)&&w.push("-");f=h&&tp((2147483647-g)/m)&&l("overflow");g+=(d-h)*m;h=d;for(c=0;c=a+26?26:d-a;if(n= 0x80 (not a basic code point)","invalid-input":"Invalid input"},p=Math.floor,r=String.fromCharCode,B;x={version:"1.3.2",ucs2:{decode:b,encode:m},decode:h,encode:q,toASCII:function(b){return k(b,function(b){return y.test(b)?"xn--"+q(b):b})},toUnicode:function(b){return k(b,function(b){return E.test(b)?h(b.slice(4).toLowerCase()):b})}};if("function"== -typeof define&&"object"==typeof define.amd&&define.amd)define("punycode",function(){return x});else if(A&&C)if(module.exports==A)C.exports=x;else for(B in x)x.hasOwnProperty(B)&&(A[B]=x[B]);else f.punycode=x})(this); -(function(f,l){"object"===typeof module&&module.exports?module.exports=l():"function"===typeof define&&define.amd?define(l):f.SecondLevelDomains=l(f)})(this,function(f){var l=f&&f.SecondLevelDomains,g={list:{ac:" com gov mil net org ",ae:" ac co gov mil name net org pro sch ",af:" com edu gov net org ",al:" com edu gov mil net org ",ao:" co ed gv it og pb ",ar:" com edu gob gov int mil net org tur ",at:" ac co gv or ",au:" asn com csiro edu gov id net org ",ba:" co com edu gov mil net org rs unbi unmo unsa untz unze ", +(function(f,m){"object"===typeof module&&module.exports?module.exports=m():"function"===typeof define&&define.amd?define(m):f.IPv6=m(f)})(this,function(f){var m=f&&f.IPv6;return{best:function(g){g=g.toLowerCase().split(":");var k=g.length,b=8;""===g[0]&&""===g[1]&&""===g[2]?(g.shift(),g.shift()):""===g[0]&&""===g[1]?g.shift():""===g[k-1]&&""===g[k-2]&&g.pop();k=g.length;-1!==g[k-1].indexOf(".")&&(b=7);var l;for(l=0;lf;f++)if("0"===k[0]&&1f&&(k=h,f=m)):"0"===g[l]&&(q=!0,h=l,m=1);m>f&&(k=h,f=m);1=f&&h>>10&1023|55296),b=56320|b&1023);return e+=r(b)}).join("")}function A(b,e){return b+22+75*(26>b)-((0!=e)<<5)}function v(b,e,h){var g=0;b=h?p(b/700):b>>1;for(b+=p(b/e);455d&&(d=0);for(n=0;n=h&&m("invalid-input");w=b.charCodeAt(d++); +w=10>w-48?w-22:26>w-65?w-65:26>w-97?w-97:36;(36<=w||w>p((2147483647-f)/g))&&m("overflow");f+=w*g;k=t<=c?1:t>=c+26?26:t-c;if(wp(2147483647/w)&&m("overflow");g*=w}g=e.length+1;c=v(f-n,g,0==n);p(f/g)>2147483647-a&&m("overflow");a+=p(f/g);f%=g;e.splice(f++,0,a)}return l(e)}function q(e){var h,g,f,k,a,c,d,n,t,w=[],q,l,z;e=b(e);q=e.length;h=128;g=0;a=72;for(c=0;ct&&w.push(r(t));for((f=k=w.length)&&w.push("-");f=h&&tp((2147483647-g)/l)&&m("overflow");g+=(d-h)*l;h=d;for(c=0;c=a+26?26:d-a;if(n= 0x80 (not a basic code point)","invalid-input":"Invalid input"},p=Math.floor,r=String.fromCharCode,B;x={version:"1.3.2",ucs2:{decode:b,encode:l},decode:h,encode:q,toASCII:function(b){return k(b,function(b){return y.test(b)?"xn--"+q(b):b})},toUnicode:function(b){return k(b,function(b){return E.test(b)?h(b.slice(4).toLowerCase()):b})}};if("function"== +typeof define&&"object"==typeof define.amd&&define.amd)define("punycode",function(){return x});else if(z&&C)if(module.exports==z)C.exports=x;else for(B in x)x.hasOwnProperty(B)&&(z[B]=x[B]);else f.punycode=x})(this); +(function(f,m){"object"===typeof module&&module.exports?module.exports=m():"function"===typeof define&&define.amd?define(m):f.SecondLevelDomains=m(f)})(this,function(f){var m=f&&f.SecondLevelDomains,g={list:{ac:" com gov mil net org ",ae:" ac co gov mil name net org pro sch ",af:" com edu gov net org ",al:" com edu gov mil net org ",ao:" co ed gv it og pb ",ar:" com edu gob gov int mil net org tur ",at:" ac co gv or ",au:" asn com csiro edu gov id net org ",ba:" co com edu gov mil net org rs unbi unmo unsa untz unze ", bb:" biz co com edu gov info net org store tv ",bh:" biz cc com edu gov info net org ",bn:" com edu gov net org ",bo:" com edu gob gov int mil net org tv ",br:" adm adv agr am arq art ato b bio blog bmd cim cng cnt com coop ecn edu eng esp etc eti far flog fm fnd fot fst g12 ggf gov imb ind inf jor jus lel mat med mil mus net nom not ntr odo org ppg pro psc psi qsl rec slg srv tmp trd tur tv vet vlog wiki zlg ",bs:" com edu gov net org ",bz:" du et om ov rg ",ca:" ab bc mb nb nf nl ns nt nu on pe qc sk yk ", ck:" biz co edu gen gov info net org ",cn:" ac ah bj com cq edu fj gd gov gs gx gz ha hb he hi hl hn jl js jx ln mil net nm nx org qh sc sd sh sn sx tj tw xj xz yn zj ",co:" com edu gov mil net nom org ",cr:" ac c co ed fi go or sa ",cy:" ac biz com ekloges gov ltd name net org parliament press pro tm ","do":" art com edu gob gov mil net org sld web ",dz:" art asso com edu gov net org pol ",ec:" com edu fin gov info med mil net org pro ",eg:" com edu eun gov mil name net org sci ",er:" com edu gov ind mil net org rochest w ", es:" com edu gob nom org ",et:" biz com edu gov info name net org ",fj:" ac biz com info mil name net org pro ",fk:" ac co gov net nom org ",fr:" asso com f gouv nom prd presse tm ",gg:" co net org ",gh:" com edu gov mil org ",gn:" ac com gov net org ",gr:" com edu gov mil net org ",gt:" com edu gob ind mil net org ",gu:" com edu gov net org ",hk:" com edu gov idv net org ",hu:" 2000 agrar bolt casino city co erotica erotika film forum games hotel info ingatlan jogasz konyvelo lakas media news org priv reklam sex shop sport suli szex tm tozsde utazas video ", @@ -21,12 +21,12 @@ tw:" club com ebiz edu game gov idv mil net org ",mu:" ac co com gov net or org rw:" ac co com edu gouv gov int mil net ",sa:" com edu gov med net org pub sch ",sd:" com edu gov info med net org tv ",se:" a ac b bd c d e f g h i k l m n o org p parti pp press r s t tm u w x y z ",sg:" com edu gov idn net org per ",sn:" art com edu gouv org perso univ ",sy:" com edu gov mil net news org ",th:" ac co go in mi net or ",tj:" ac biz co com edu go gov info int mil name net nic org test web ",tn:" agrinet com defense edunet ens fin gov ind info intl mincom nat net org perso rnrt rns rnu tourism ", tz:" ac co go ne or ",ua:" biz cherkassy chernigov chernovtsy ck cn co com crimea cv dn dnepropetrovsk donetsk dp edu gov if in ivano-frankivsk kh kharkov kherson khmelnitskiy kiev kirovograd km kr ks kv lg lugansk lutsk lviv me mk net nikolaev od odessa org pl poltava pp rovno rv sebastopol sumy te ternopil uzhgorod vinnica vn zaporizhzhe zhitomir zp zt ",ug:" ac co go ne or org sc ",uk:" ac bl british-library co cym gov govt icnet jet lea ltd me mil mod national-library-scotland nel net nhs nic nls org orgn parliament plc police sch scot soc ", us:" dni fed isa kids nsn ",uy:" com edu gub mil net org ",ve:" co com edu gob info mil net org web ",vi:" co com k12 net org ",vn:" ac biz com edu gov health info int name net org pro ",ye:" co com gov ltd me net org plc ",yu:" ac co edu gov org ",za:" ac agric alt bourse city co cybernet db edu gov grondar iaccess imt inca landesign law mil net ngo nis nom olivetti org pix school tm web ",zm:" ac co com edu gov net org sch "},has:function(f){var b=f.lastIndexOf(".");if(0>=b||b>=f.length-1)return!1; -var k=f.lastIndexOf(".",b-1);if(0>=k||k>=b-1)return!1;var l=g.list[f.slice(b+1)];return l?0<=l.indexOf(" "+f.slice(k+1,b)+" "):!1},is:function(f){var b=f.lastIndexOf(".");if(0>=b||b>=f.length-1||0<=f.lastIndexOf(".",b-1))return!1;var k=g.list[f.slice(b+1)];return k?0<=k.indexOf(" "+f.slice(0,b)+" "):!1},get:function(f){var b=f.lastIndexOf(".");if(0>=b||b>=f.length-1)return null;var k=f.lastIndexOf(".",b-1);if(0>=k||k>=b-1)return null;var l=g.list[f.slice(b+1)];return!l||0>l.indexOf(" "+f.slice(k+ -1,b)+" ")?null:f.slice(k+1)},noConflict:function(){f.SecondLevelDomains===this&&(f.SecondLevelDomains=l);return this}};return g}); -(function(f,l){"object"===typeof module&&module.exports?module.exports=l(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"===typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],l):f.URI=l(f.punycode,f.IPv6,f.SecondLevelDomains,f)})(this,function(f,l,g,k){function b(a,c){var d=1<=arguments.length,n=2<=arguments.length;if(!(this instanceof b))return d?n?new b(a,c):new b(a):new b;if(void 0===a){if(d)throw new TypeError("undefined is not a valid argument for URI"); -a="undefined"!==typeof location?location.href+"":""}if(null===a&&d)throw new TypeError("null is not a valid argument for URI");this.href(a);return void 0!==c?this.absoluteTo(c):this}function m(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function z(a){return void 0===a?"Undefined":String(Object.prototype.toString.call(a)).slice(8,-1)}function v(a){return"Array"===z(a)}function h(a,c){var d={},b,t;if("RegExp"===z(c))d=null;else if(v(c))for(b=0,t=c.length;b=k||k>=b-1)return!1;var m=g.list[f.slice(b+1)];return m?0<=m.indexOf(" "+f.slice(k+1,b)+" "):!1},is:function(f){var b=f.lastIndexOf(".");if(0>=b||b>=f.length-1||0<=f.lastIndexOf(".",b-1))return!1;var k=g.list[f.slice(b+1)];return k?0<=k.indexOf(" "+f.slice(0,b)+" "):!1},get:function(f){var b=f.lastIndexOf(".");if(0>=b||b>=f.length-1)return null;var k=f.lastIndexOf(".",b-1);if(0>=k||k>=b-1)return null;var m=g.list[f.slice(b+1)];return!m||0>m.indexOf(" "+f.slice(k+ +1,b)+" ")?null:f.slice(k+1)},noConflict:function(){f.SecondLevelDomains===this&&(f.SecondLevelDomains=m);return this}};return g}); +(function(f,m){"object"===typeof module&&module.exports?module.exports=m(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"===typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],m):f.URI=m(f.punycode,f.IPv6,f.SecondLevelDomains,f)})(this,function(f,m,g,k){function b(a,c){var d=1<=arguments.length,n=2<=arguments.length;if(!(this instanceof b))return d?n?new b(a,c):new b(a):new b;if(void 0===a){if(d)throw new TypeError("undefined is not a valid argument for URI"); +a="undefined"!==typeof location?location.href+"":""}if(null===a&&d)throw new TypeError("null is not a valid argument for URI");this.href(a);return void 0!==c?this.absoluteTo(c):this}function l(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function A(a){return void 0===a?"Undefined":String(Object.prototype.toString.call(a)).slice(8,-1)}function v(a){return"Array"===A(a)}function h(a,c){var d={},b,t;if("RegExp"===A(c))d=null;else if(v(c))for(b=0,t=c.length;b]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u2018\u2019]))/ig;b.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u201e\u2018\u2019]+$/,parens:/(\([^\)]*\)|\[[^\]]*\]|\{[^}]*\}|<[^>]*>)/g};b.defaultPorts={http:"80",https:"443",ftp:"21", gopher:"70",ws:"80",wss:"443"};b.invalid_hostname_characters=/[^a-zA-Z0-9\.-]/;b.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src",audio:"src",video:"src"};b.getDomAttribute=function(a){if(a&&a.nodeName){var c=a.nodeName.toLowerCase();if("input"!==c||"image"===a.type)return b.domAttributes[c]}};b.encode=x;b.decode=decodeURIComponent;b.iso8859=function(){b.encode=escape;b.decode= @@ -40,35 +40,35 @@ c.port&&(c.port=null);else{var e=a.indexOf(":");b=a.indexOf("/");e=a.indexOf(":" d[h].push(f)}else d[h]=f;return d};b.build=function(a){var c="";a.protocol&&(c+=a.protocol+":");a.urn||!c&&!a.hostname||(c+="//");c+=b.buildAuthority(a)||"";"string"===typeof a.path&&("/"!==a.path.charAt(0)&&"string"===typeof a.hostname&&(c+="/"),c+=a.path);"string"===typeof a.query&&a.query&&(c+="?"+a.query);"string"===typeof a.fragment&&a.fragment&&(c+="#"+a.fragment);return c};b.buildHost=function(a){var c="";if(a.hostname)c=b.ip6_expression.test(a.hostname)?c+("["+a.hostname+"]"):c+a.hostname; else return"";a.port&&(c+=":"+a.port);return c};b.buildAuthority=function(a){return b.buildUserinfo(a)+b.buildHost(a)};b.buildUserinfo=function(a){var c="";a.username&&(c+=b.encode(a.username));a.password&&(c+=":"+b.encode(a.password));c&&(c+="@");return c};b.buildQuery=function(a,c,d){var n="",e,f,h,g;for(f in a)if(p.call(a,f)&&f)if(v(a[f]))for(e={},h=0,g=a[f].length;hb)return a.charAt(0)===c.charAt(0)&&"/"===a.charAt(0)?"/":"";if("/"!==a.charAt(b)||"/"!==c.charAt(b))b=a.substring(0,b).lastIndexOf("/");return a.substring(0,b+1)};b.withinString=function(a,c,d){d||(d={}); -var e=d.start||b.findUri.start,f=d.end||b.findUri.end,h=d.trim||b.findUri.trim,g=d.parens||b.findUri.parens,q=/[a-z0-9-]=["']?$/i;for(e.lastIndex=0;;){var k=e.exec(a);if(!k)break;k=k.index;if(d.ignoreHtml){var l=a.slice(Math.max(k-3,0),k);if(l&&q.test(l))continue}for(var p=k+a.slice(k).search(f),l=a.slice(k,p),p=-1;;){var m=g.exec(l);if(!m)break;p=Math.max(p,m.index+m[0].length)}l=-1d.length)return this._parts.hostname;d=this._parts.hostname.length-this.tld(c).length-1;d=this._parts.hostname.lastIndexOf(".",d-1)+1;return this._parts.hostname.substring(d)||""}if(!a)throw new TypeError("cannot set domain empty");b.ensureValidHostname(a); -!this._parts.hostname||this.is("IP")?this._parts.hostname=a:(d=new RegExp(m(this.domain())+"$"),this._parts.hostname=this._parts.hostname.replace(d,a));this.build(!c);return this};e.tld=function(a,c){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(c=a,a=void 0);if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var d=this._parts.hostname.lastIndexOf("."),d=this._parts.hostname.substring(d+1);return!0!==c&&g&&g.list[d.toLowerCase()]?g.get(this._parts.hostname)||d:d}if(a)if(a.match(/[^a-zA-Z0-9-]/))if(g&& -g.is(a))d=new RegExp(m(this.tld())+"$"),this._parts.hostname=this._parts.hostname.replace(d,a);else throw new TypeError('TLD "'+a+'" contains characters other than [A-Z0-9]');else{if(!this._parts.hostname||this.is("IP"))throw new ReferenceError("cannot set TLD on non-domain host");d=new RegExp(m(this.tld())+"$");this._parts.hostname=this._parts.hostname.replace(d,a)}else throw new TypeError("cannot set TLD empty");this.build(!c);return this};e.directory=function(a,c){if(this._parts.urn)return void 0=== -a?"":this;if(void 0===a||!0===a){if(!this._parts.path&&!this._parts.hostname)return"";if("/"===this._parts.path)return"/";var d=this._parts.path.length-this.filename().length-1,d=this._parts.path.substring(0,d)||(this._parts.hostname?"/":"");return a?b.decodePath(d):d}d=this._parts.path.length-this.filename().length;d=this._parts.path.substring(0,d);d=new RegExp("^"+m(d));this.is("relative")||(a||(a="/"),"/"!==a.charAt(0)&&(a="/"+a));a&&"/"!==a.charAt(a.length-1)&&(a+="/");a=b.recodePath(a);this._parts.path= -this._parts.path.replace(d,a);this.build(!c);return this};e.filename=function(a,c){if(this._parts.urn)return void 0===a?"":this;if("string"!==typeof a){if(!this._parts.path||"/"===this._parts.path)return"";var d=this._parts.path.lastIndexOf("/"),d=this._parts.path.substring(d+1);return a?b.decodePathSegment(d):d}d=!1;"/"===a.charAt(0)&&(a=a.substring(1));a.match(/\.?\//)&&(d=!0);var e=new RegExp(m(this.filename())+"$");a=b.recodePath(a);this._parts.path=this._parts.path.replace(e,a);d?this.normalizePath(c): -this.build(!c);return this};e.suffix=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path||"/"===this._parts.path)return"";var d=this.filename(),e=d.lastIndexOf(".");if(-1===e)return"";d=d.substring(e+1);d=/^[a-z0-9%]+$/i.test(d)?d:"";return a?b.decodePathSegment(d):d}"."===a.charAt(0)&&(a=a.substring(1));if(d=this.suffix())e=a?new RegExp(m(d)+"$"):new RegExp(m("."+d)+"$");else{if(!a)return this;this._parts.path+="."+b.recodePath(a)}e&&(a=b.recodePath(a), +!this._parts.hostname||this.is("IP")?this._parts.hostname=a:(d=new RegExp(l(this.domain())+"$"),this._parts.hostname=this._parts.hostname.replace(d,a));this.build(!c);return this};e.tld=function(a,c){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(c=a,a=void 0);if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var d=this._parts.hostname.lastIndexOf("."),d=this._parts.hostname.substring(d+1);return!0!==c&&g&&g.list[d.toLowerCase()]?g.get(this._parts.hostname)||d:d}if(a)if(a.match(/[^a-zA-Z0-9-]/))if(g&& +g.is(a))d=new RegExp(l(this.tld())+"$"),this._parts.hostname=this._parts.hostname.replace(d,a);else throw new TypeError('TLD "'+a+'" contains characters other than [A-Z0-9]');else{if(!this._parts.hostname||this.is("IP"))throw new ReferenceError("cannot set TLD on non-domain host");d=new RegExp(l(this.tld())+"$");this._parts.hostname=this._parts.hostname.replace(d,a)}else throw new TypeError("cannot set TLD empty");this.build(!c);return this};e.directory=function(a,c){if(this._parts.urn)return void 0=== +a?"":this;if(void 0===a||!0===a){if(!this._parts.path&&!this._parts.hostname)return"";if("/"===this._parts.path)return"/";var d=this._parts.path.length-this.filename().length-1,d=this._parts.path.substring(0,d)||(this._parts.hostname?"/":"");return a?b.decodePath(d):d}d=this._parts.path.length-this.filename().length;d=this._parts.path.substring(0,d);d=new RegExp("^"+l(d));this.is("relative")||(a||(a="/"),"/"!==a.charAt(0)&&(a="/"+a));a&&"/"!==a.charAt(a.length-1)&&(a+="/");a=b.recodePath(a);this._parts.path= +this._parts.path.replace(d,a);this.build(!c);return this};e.filename=function(a,c){if(this._parts.urn)return void 0===a?"":this;if("string"!==typeof a){if(!this._parts.path||"/"===this._parts.path)return"";var d=this._parts.path.lastIndexOf("/"),d=this._parts.path.substring(d+1);return a?b.decodePathSegment(d):d}d=!1;"/"===a.charAt(0)&&(a=a.substring(1));a.match(/\.?\//)&&(d=!0);var e=new RegExp(l(this.filename())+"$");a=b.recodePath(a);this._parts.path=this._parts.path.replace(e,a);d?this.normalizePath(c): +this.build(!c);return this};e.suffix=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path||"/"===this._parts.path)return"";var d=this.filename(),e=d.lastIndexOf(".");if(-1===e)return"";d=d.substring(e+1);d=/^[a-z0-9%]+$/i.test(d)?d:"";return a?b.decodePathSegment(d):d}"."===a.charAt(0)&&(a=a.substring(1));if(d=this.suffix())e=a?new RegExp(l(d)+"$"):new RegExp(l("."+d)+"$");else{if(!a)return this;this._parts.path+="."+b.recodePath(a)}e&&(a=b.recodePath(a), this._parts.path=this._parts.path.replace(e,a));this.build(!c);return this};e.segment=function(a,c,d){var b=this._parts.urn?":":"/",e=this.path(),f="/"===e.substring(0,1),e=e.split(b);void 0!==a&&"number"!==typeof a&&(d=c,c=a,a=void 0);if(void 0!==a&&"number"!==typeof a)throw Error('Bad segment "'+a+'", must be 0-based integer');f&&e.shift();0>a&&(a=Math.max(e.length+a,0));if(void 0===c)return void 0===a?e:e[a];if(null===a||void 0===e[a])if(v(c)){e=[];a=0;for(var h=c.length;a{}"`^| \\]/;g.expand=function(b,f){var h=v[b.operator],k=h.named?"Named":"Unnamed",l=b.variables,q=[],m,y,u;for(u=0;y=l[u];u++)if(m=f.get(y.name),m.val.length){if(1{}"`^| \\]/;g.expand=function(b,f){var h=v[b.operator],k=h.named?"Named":"Unnamed",m=b.variables,q=[],l,y,u;for(u=0;y=m[u];u++)if(l=f.get(y.name),l.val.length){if(1 Date: Tue, 28 Feb 2017 04:22:06 +0800 Subject: [PATCH 13/44] fix(absoluteTo): return original URI for URI with scheme closes #328 #329 --- src/URI.js | 5 ++++- test/test.js | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/URI.js b/src/URI.js index 0f023981..d8492ecc 100644 --- a/src/URI.js +++ b/src/URI.js @@ -2077,7 +2077,10 @@ base = new URI(base); } - if (!resolved._parts.protocol) { + if (resolved._parts.protocol) { + // Directly returns even if this._parts.hostname is empty. + return resolved; + } else { resolved._parts.protocol = base._parts.protocol; } diff --git a/test/test.js b/test/test.js index 8745d608..dc07acf0 100644 --- a/test/test.js +++ b/test/test.js @@ -1342,6 +1342,16 @@ url: 'http://github.com//the_relative_url', base: 'http://example.com/foo/bar', result: 'http://github.com//the_relative_url' + }, { + name: 'absolute passthru - file:/// - urljoin (#328)', + url: 'file:///C:/skyclan/snipkit', + base: 'http://example.com/foo/bar', + result: 'file:///C:/skyclan/snipkit' + }, { + name: 'absolute passthru - generic empty-hostname - urljoin (#328)', + url: 'http:///foo', + base: 'http://example.com/foo/bar', + result: 'http:///foo' }, { name: 'file paths - urljoin', url: 'anotherFile', From c493005bbf8743cf04a0c298e83e8e9413505d15 Mon Sep 17 00:00:00 2001 From: Rodney Rehm Date: Mon, 27 Feb 2017 21:26:14 +0100 Subject: [PATCH 14/44] chore(build): bumping to version 1.18.8 --- CHANGELOG.md | 4 ++++ bower.json | 2 +- build.js | 2 +- package.json | 2 +- src/IPv6.js | 2 +- src/SecondLevelDomains.js | 2 +- src/URI.js | 4 ++-- src/URITemplate.js | 2 +- src/jquery.URI.js | 2 +- 9 files changed, 13 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1ce62a6..783c8c2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ The release notes tracked in this document are also made available on the [releases page](https://github.com/medialize/URI.js/releases) +### 1.18.8 (February 27th 2017) ### + +* fixing [`.absoluteTo()`](http://medialize.github.io/URI.js/docs.html#absoluteto) to not resolve URIs containing a scheme - [Issue #328](https://github.com/medialize/URI.js/issues/328) + ### 1.18.7 (February 13th 2017) ### * fixing [`URI.withinString()`](http://medialize.github.io/URI.js/docs.html#static-withinString) to ignore `www.` and `http://.` - [Issue #327](https://github.com/medialize/URI.js/issues/327) diff --git a/bower.json b/bower.json index c9fa14e9..b281ed44 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "urijs", - "version": "1.18.7", + "version": "1.18.8", "main": "src/URI.js", "ignore": [ ".*", diff --git a/build.js b/build.js index 26b75e09..a3c7dc51 100644 --- a/build.js +++ b/build.js @@ -29,7 +29,7 @@ function build(files) { output_format: "text", output_info: "compiled_code" }, function(data) { - var code = "/*! URI.js v1.18.7 http://medialize.github.io/URI.js/ */\n/* build contains: " + files.join(', ') + " */\n" + data; + var code = "/*! URI.js v1.18.8 http://medialize.github.io/URI.js/ */\n/* build contains: " + files.join(', ') + " */\n" + data; $progress.hide(); $out.val(code).parent().show(); $out.prev().find('a').remove(); diff --git a/package.json b/package.json index 7756ca43..06ccbbf8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "urijs", - "version": "1.18.7", + "version": "1.18.8", "title": "URI.js - Mutating URLs", "author": { "name": "Rodney Rehm", diff --git a/src/IPv6.js b/src/IPv6.js index 145e5176..ba79b8bb 100644 --- a/src/IPv6.js +++ b/src/IPv6.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * IPv6 Support * - * Version: 1.18.7 + * Version: 1.18.8 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/SecondLevelDomains.js b/src/SecondLevelDomains.js index 3139414a..d164c7d1 100644 --- a/src/SecondLevelDomains.js +++ b/src/SecondLevelDomains.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * Second Level Domain (SLD) Support * - * Version: 1.18.7 + * Version: 1.18.8 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/URI.js b/src/URI.js index d8492ecc..e50a476b 100644 --- a/src/URI.js +++ b/src/URI.js @@ -1,7 +1,7 @@ /*! * URI.js - Mutating URLs * - * Version: 1.18.7 + * Version: 1.18.8 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ @@ -77,7 +77,7 @@ return this; } - URI.version = '1.18.7'; + URI.version = '1.18.8'; var p = URI.prototype; var hasOwn = Object.prototype.hasOwnProperty; diff --git a/src/URITemplate.js b/src/URITemplate.js index 5730a27b..3272785f 100644 --- a/src/URITemplate.js +++ b/src/URITemplate.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * URI Template Support - http://tools.ietf.org/html/rfc6570 * - * Version: 1.18.7 + * Version: 1.18.8 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/jquery.URI.js b/src/jquery.URI.js index b9a31e70..9c00dd24 100644 --- a/src/jquery.URI.js +++ b/src/jquery.URI.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * jQuery Plugin * - * Version: 1.18.7 + * Version: 1.18.8 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/jquery-uri-plugin.html From d6691b3c601cc27acb990ab8eeef3138c12f5453 Mon Sep 17 00:00:00 2001 From: Rodney Rehm Date: Mon, 27 Feb 2017 21:31:32 +0100 Subject: [PATCH 15/44] chore(dist): updating distributables to version 1.18.8 --- src/URI.min.js | 6 +++--- src/jquery.URI.min.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/URI.min.js b/src/URI.min.js index 00c48fc1..e5cf72e6 100644 --- a/src/URI.min.js +++ b/src/URI.min.js @@ -1,4 +1,4 @@ -/*! URI.js v1.18.7 http://medialize.github.io/URI.js/ */ +/*! URI.js v1.18.8 http://medialize.github.io/URI.js/ */ /* build contains: IPv6.js, punycode.js, SecondLevelDomains.js, URI.js, URITemplate.js */ (function(f,m){"object"===typeof module&&module.exports?module.exports=m():"function"===typeof define&&define.amd?define(m):f.IPv6=m(f)})(this,function(f){var m=f&&f.IPv6;return{best:function(g){g=g.toLowerCase().split(":");var k=g.length,b=8;""===g[0]&&""===g[1]&&""===g[2]?(g.shift(),g.shift()):""===g[0]&&""===g[1]?g.shift():""===g[k-1]&&""===g[k-2]&&g.pop();k=g.length;-1!==g[k-1].indexOf(".")&&(b=7);var l;for(l=0;lf;f++)if("0"===k[0]&&1f&&(k=h,f=m)):"0"===g[l]&&(q=!0,h=l,m=1);m>f&&(k=h,f=m);1=k||k>=b-1)return!1;var m=g.list[f.slice(b+1)] (function(f,m){"object"===typeof module&&module.exports?module.exports=m(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"===typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],m):f.URI=m(f.punycode,f.IPv6,f.SecondLevelDomains,f)})(this,function(f,m,g,k){function b(a,c){var d=1<=arguments.length,n=2<=arguments.length;if(!(this instanceof b))return d?n?new b(a,c):new b(a):new b;if(void 0===a){if(d)throw new TypeError("undefined is not a valid argument for URI"); a="undefined"!==typeof location?location.href+"":""}if(null===a&&d)throw new TypeError("null is not a valid argument for URI");this.href(a);return void 0!==c?this.absoluteTo(c):this}function l(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function A(a){return void 0===a?"Undefined":String(Object.prototype.toString.call(a)).slice(8,-1)}function v(a){return"Array"===A(a)}function h(a,c){var d={},b,t;if("RegExp"===A(c))d=null;else if(v(c))for(b=0,t=c.length;b]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u2018\u2019]))/ig;b.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u201e\u2018\u2019]+$/,parens:/(\([^\)]*\)|\[[^\]]*\]|\{[^}]*\}|<[^>]*>)/g};b.defaultPorts={http:"80",https:"443",ftp:"21", gopher:"70",ws:"80",wss:"443"};b.invalid_hostname_characters=/[^a-zA-Z0-9\.-]/;b.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src",audio:"src",video:"src"};b.getDomAttribute=function(a){if(a&&a.nodeName){var c=a.nodeName.toLowerCase();if("input"!==c||"image"===a.type)return b.domAttributes[c]}};b.encode=x;b.decode=decodeURIComponent;b.iso8859=function(){b.encode=escape;b.decode= @@ -73,7 +73,7 @@ this._parts.port===b.defaultPorts[this._parts.protocol]&&(this._parts.port=null, "")&&(e=e[0]);for(;;){f=c.search(/\/\.\.(\/|$)/);if(-1===f)break;else if(0===f){c=c.substring(3);continue}h=c.substring(0,f).lastIndexOf("/");-1===h&&(h=f);c=c.substring(0,h)+c.substring(f+3)}d&&this.is("relative")&&(c=e+c.substring(1));this._parts.path=c;this.build(!a);return this};e.normalizePathname=e.normalizePath;e.normalizeQuery=function(a){"string"===typeof this._parts.query&&(this._parts.query.length?this.query(b.parseQuery(this._parts.query,this._parts.escapeQuerySpace)):this._parts.query= null,this.build(!a));return this};e.normalizeFragment=function(a){this._parts.fragment||(this._parts.fragment=null,this.build(!a));return this};e.normalizeSearch=e.normalizeQuery;e.normalizeHash=e.normalizeFragment;e.iso8859=function(){var a=b.encode,c=b.decode;b.encode=escape;b.decode=decodeURIComponent;try{this.normalize()}finally{b.encode=a,b.decode=c}return this};e.unicode=function(){var a=b.encode,c=b.decode;b.encode=x;b.decode=unescape;try{this.normalize()}finally{b.encode=a,b.decode=c}return this}; e.readable=function(){var a=this.clone();a.username("").password("").normalize();var c="";a._parts.protocol&&(c+=a._parts.protocol+"://");a._parts.hostname&&(a.is("punycode")&&f?(c+=f.toUnicode(a._parts.hostname),a._parts.port&&(c+=":"+a._parts.port)):c+=a.host());a._parts.hostname&&a._parts.path&&"/"!==a._parts.path.charAt(0)&&(c+="/");c+=a.path(!0);if(a._parts.query){for(var d="",e=0,h=a._parts.query.split("&"),g=h.length;e Date: Mon, 6 Mar 2017 11:53:41 +0100 Subject: [PATCH 16/44] feature(templates): adding strict mode for placeholder replacement (#331) When activated, strict mode makes URITemplate throw instead of silently replacing missing values by empty strings. --- src/URITemplate.js | 9 ++++++--- test/test_template.js | 6 ++++++ uri-template.html | 5 +++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/URITemplate.js b/src/URITemplate.js index 3272785f..93fd3dea 100644 --- a/src/URITemplate.js +++ b/src/URITemplate.js @@ -140,7 +140,7 @@ URITemplate.LITERAL_PATTERN = /[<>{}"`^| \\]/; // expand parsed expression (expression, not template!) - URITemplate.expand = function(expression, data) { + URITemplate.expand = function(expression, data, opts) { // container for defined options for the given operator var options = operators[expression.operator]; // expansion type (include keys or not) @@ -154,6 +154,9 @@ for (i = 0; (variable = variables[i]); i++) { // fetch simplified data source d = data.get(variable.name); + if (d.type === 0 && opts && opts.strict) { + throw new Error('Missing expansion value for variable "' + variable.name + '"'); + } if (!d.val.length) { if (d.type) { // empty variables (empty string) @@ -320,7 +323,7 @@ }; // expand template through given data map - p.expand = function(data) { + p.expand = function(data, opts) { var result = ''; if (!this.parts || !this.parts.length) { @@ -340,7 +343,7 @@ // literal string ? this.parts[i] // expression - : URITemplate.expand(this.parts[i], data); + : URITemplate.expand(this.parts[i], data, opts); /*jshint laxbreak: false */ } diff --git a/test/test_template.js b/test/test_template.js index 16db0179..b2b5f037 100644 --- a/test/test_template.js +++ b/test/test_template.js @@ -408,4 +408,10 @@ }, Error, 'Failing invalid literal'); }); + test('Strict mode', function () { + raises(function() { + new URITemplate("/{foo}/bar").expand({ foobar: 123 }, { strict: true }); + }, Error, 'Missing expansion value for variable in strict mode.'); + }); + })(); diff --git a/uri-template.html b/uri-template.html index d49065c9..c9407629 100644 --- a/uri-template.html +++ b/uri-template.html @@ -107,6 +107,11 @@

Using URI Templates

template.expand({file : function(key) { return "hello world.html"; }}); + +// Using strict mode +var template = new URITemplate("http://example.org/{file}"); +var result = template.expand({filename: "hello world.html"}, { strict: true }); +// Uncaught Error: Missing expansion value for variable "file" From 303817f73df94ad4858bf358382877f2c26ab54e Mon Sep 17 00:00:00 2001 From: Rodney Rehm Date: Mon, 6 Mar 2017 11:55:18 +0100 Subject: [PATCH 17/44] chore(build): bumping to version 1.18.9 --- CHANGELOG.md | 4 ++++ bower.json | 2 +- build.js | 2 +- package.json | 2 +- src/IPv6.js | 2 +- src/SecondLevelDomains.js | 2 +- src/URI.js | 4 ++-- src/URITemplate.js | 2 +- src/jquery.URI.js | 2 +- 9 files changed, 13 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 783c8c2c..0b545990 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ The release notes tracked in this document are also made available on the [releases page](https://github.com/medialize/URI.js/releases) +### 1.18.9 (March 6th 2017) ### + +* adding option `strict` to [`URITemplate()`](http://medialize.github.io/URI.js/uri-template.html) in order to throw an exception in case a placeholder could not be replaced - [PR #330](https://github.com/medialize/URI.js/issues/330) + ### 1.18.8 (February 27th 2017) ### * fixing [`.absoluteTo()`](http://medialize.github.io/URI.js/docs.html#absoluteto) to not resolve URIs containing a scheme - [Issue #328](https://github.com/medialize/URI.js/issues/328) diff --git a/bower.json b/bower.json index b281ed44..6e11cc36 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "urijs", - "version": "1.18.8", + "version": "1.18.9", "main": "src/URI.js", "ignore": [ ".*", diff --git a/build.js b/build.js index a3c7dc51..f9158f99 100644 --- a/build.js +++ b/build.js @@ -29,7 +29,7 @@ function build(files) { output_format: "text", output_info: "compiled_code" }, function(data) { - var code = "/*! URI.js v1.18.8 http://medialize.github.io/URI.js/ */\n/* build contains: " + files.join(', ') + " */\n" + data; + var code = "/*! URI.js v1.18.9 http://medialize.github.io/URI.js/ */\n/* build contains: " + files.join(', ') + " */\n" + data; $progress.hide(); $out.val(code).parent().show(); $out.prev().find('a').remove(); diff --git a/package.json b/package.json index 06ccbbf8..fefdd1c7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "urijs", - "version": "1.18.8", + "version": "1.18.9", "title": "URI.js - Mutating URLs", "author": { "name": "Rodney Rehm", diff --git a/src/IPv6.js b/src/IPv6.js index ba79b8bb..7f1b7c9e 100644 --- a/src/IPv6.js +++ b/src/IPv6.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * IPv6 Support * - * Version: 1.18.8 + * Version: 1.18.9 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/SecondLevelDomains.js b/src/SecondLevelDomains.js index d164c7d1..ac9e3e62 100644 --- a/src/SecondLevelDomains.js +++ b/src/SecondLevelDomains.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * Second Level Domain (SLD) Support * - * Version: 1.18.8 + * Version: 1.18.9 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/URI.js b/src/URI.js index e50a476b..bc96cf07 100644 --- a/src/URI.js +++ b/src/URI.js @@ -1,7 +1,7 @@ /*! * URI.js - Mutating URLs * - * Version: 1.18.8 + * Version: 1.18.9 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ @@ -77,7 +77,7 @@ return this; } - URI.version = '1.18.8'; + URI.version = '1.18.9'; var p = URI.prototype; var hasOwn = Object.prototype.hasOwnProperty; diff --git a/src/URITemplate.js b/src/URITemplate.js index 93fd3dea..4a25a9d5 100644 --- a/src/URITemplate.js +++ b/src/URITemplate.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * URI Template Support - http://tools.ietf.org/html/rfc6570 * - * Version: 1.18.8 + * Version: 1.18.9 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/jquery.URI.js b/src/jquery.URI.js index 9c00dd24..7d87fef3 100644 --- a/src/jquery.URI.js +++ b/src/jquery.URI.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * jQuery Plugin * - * Version: 1.18.8 + * Version: 1.18.9 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/jquery-uri-plugin.html From 230da879bb3c80d58c216193ccd2b07cdd07354e Mon Sep 17 00:00:00 2001 From: Rodney Rehm Date: Mon, 6 Mar 2017 11:57:56 +0100 Subject: [PATCH 18/44] chore(dist): updating distributables to version 1.18.9 --- src/URI.min.js | 122 +++++++++++++++++++++--------------------- src/jquery.URI.min.js | 2 +- 2 files changed, 62 insertions(+), 62 deletions(-) diff --git a/src/URI.min.js b/src/URI.min.js index e5cf72e6..d24a5371 100644 --- a/src/URI.min.js +++ b/src/URI.min.js @@ -1,14 +1,14 @@ -/*! URI.js v1.18.8 http://medialize.github.io/URI.js/ */ +/*! URI.js v1.18.9 http://medialize.github.io/URI.js/ */ /* build contains: IPv6.js, punycode.js, SecondLevelDomains.js, URI.js, URITemplate.js */ -(function(f,m){"object"===typeof module&&module.exports?module.exports=m():"function"===typeof define&&define.amd?define(m):f.IPv6=m(f)})(this,function(f){var m=f&&f.IPv6;return{best:function(g){g=g.toLowerCase().split(":");var k=g.length,b=8;""===g[0]&&""===g[1]&&""===g[2]?(g.shift(),g.shift()):""===g[0]&&""===g[1]?g.shift():""===g[k-1]&&""===g[k-2]&&g.pop();k=g.length;-1!==g[k-1].indexOf(".")&&(b=7);var l;for(l=0;lf;f++)if("0"===k[0]&&1f&&(k=h,f=m)):"0"===g[l]&&(q=!0,h=l,m=1);m>f&&(k=h,f=m);1=f&&h>>10&1023|55296),b=56320|b&1023);return e+=r(b)}).join("")}function A(b,e){return b+22+75*(26>b)-((0!=e)<<5)}function v(b,e,h){var g=0;b=h?p(b/700):b>>1;for(b+=p(b/e);455d&&(d=0);for(n=0;n=h&&m("invalid-input");w=b.charCodeAt(d++); -w=10>w-48?w-22:26>w-65?w-65:26>w-97?w-97:36;(36<=w||w>p((2147483647-f)/g))&&m("overflow");f+=w*g;k=t<=c?1:t>=c+26?26:t-c;if(wp(2147483647/w)&&m("overflow");g*=w}g=e.length+1;c=v(f-n,g,0==n);p(f/g)>2147483647-a&&m("overflow");a+=p(f/g);f%=g;e.splice(f++,0,a)}return l(e)}function q(e){var h,g,f,k,a,c,d,n,t,w=[],q,l,z;e=b(e);q=e.length;h=128;g=0;a=72;for(c=0;ct&&w.push(r(t));for((f=k=w.length)&&w.push("-");f=h&&tp((2147483647-g)/l)&&m("overflow");g+=(d-h)*l;h=d;for(c=0;c=a+26?26:d-a;if(n= 0x80 (not a basic code point)","invalid-input":"Invalid input"},p=Math.floor,r=String.fromCharCode,B;x={version:"1.3.2",ucs2:{decode:b,encode:l},decode:h,encode:q,toASCII:function(b){return k(b,function(b){return y.test(b)?"xn--"+q(b):b})},toUnicode:function(b){return k(b,function(b){return E.test(b)?h(b.slice(4).toLowerCase()):b})}};if("function"== -typeof define&&"object"==typeof define.amd&&define.amd)define("punycode",function(){return x});else if(z&&C)if(module.exports==z)C.exports=x;else for(B in x)x.hasOwnProperty(B)&&(z[B]=x[B]);else f.punycode=x})(this); -(function(f,m){"object"===typeof module&&module.exports?module.exports=m():"function"===typeof define&&define.amd?define(m):f.SecondLevelDomains=m(f)})(this,function(f){var m=f&&f.SecondLevelDomains,g={list:{ac:" com gov mil net org ",ae:" ac co gov mil name net org pro sch ",af:" com edu gov net org ",al:" com edu gov mil net org ",ao:" co ed gv it og pb ",ar:" com edu gob gov int mil net org tur ",at:" ac co gv or ",au:" asn com csiro edu gov id net org ",ba:" co com edu gov mil net org rs unbi unmo unsa untz unze ", +(function(g,k){"object"===typeof module&&module.exports?module.exports=k():"function"===typeof define&&define.amd?define(k):g.IPv6=k(g)})(this,function(g){var k=g&&g.IPv6;return{best:function(h){h=h.toLowerCase().split(":");var l=h.length,b=8;""===h[0]&&""===h[1]&&""===h[2]?(h.shift(),h.shift()):""===h[0]&&""===h[1]?h.shift():""===h[l-1]&&""===h[l-2]&&h.pop();l=h.length;-1!==h[l-1].indexOf(".")&&(b=7);var m;for(m=0;mg;g++)if("0"===l[0]&&1g&&(l=f,g=k)):"0"===h[m]&&(n=!0,f=m,k=1);k>g&&(l=f,g=k);1=g&&f>>10&1023|55296),b=56320|b&1023);return e+=r(b)}).join("")}function A(b,e){return b+22+75*(26>b)-((0!=e)<<5)}function u(b,e,f){var h=0;b=f?q(b/700):b>>1;for(b+=q(b/e);455d&&(d=0);for(p=0;p=f&&k("invalid-input");w=b.charCodeAt(d++); +w=10>w-48?w-22:26>w-65?w-65:26>w-97?w-97:36;(36<=w||w>q((2147483647-g)/h))&&k("overflow");g+=w*h;l=t<=c?1:t>=c+26?26:t-c;if(wq(2147483647/w)&&k("overflow");h*=w}h=e.length+1;c=u(g-p,h,0==p);q(g/h)>2147483647-a&&k("overflow");a+=q(g/h);g%=h;e.splice(g++,0,a)}return m(e)}function n(e){var f,h,g,l,a,c,d,p,t,w=[],n,m,z;e=b(e);n=e.length;f=128;h=0;a=72;for(c=0;ct&&w.push(r(t));for((g=l=w.length)&&w.push("-");g=f&&tq((2147483647-h)/m)&&k("overflow");h+=(d-f)*m;f=d;for(c=0;c=a+26?26:d-a;if(p= 0x80 (not a basic code point)","invalid-input":"Invalid input"},q=Math.floor,r=String.fromCharCode,C;y={version:"1.3.2",ucs2:{decode:b,encode:m},decode:f,encode:n,toASCII:function(b){return l(b,function(b){return x.test(b)?"xn--"+n(b):b})},toUnicode:function(b){return l(b,function(b){return E.test(b)?f(b.slice(4).toLowerCase()):b})}};if("function"== +typeof define&&"object"==typeof define.amd&&define.amd)define("punycode",function(){return y});else if(B&&z)if(module.exports==B)z.exports=y;else for(C in y)y.hasOwnProperty(C)&&(B[C]=y[C]);else g.punycode=y})(this); +(function(g,k){"object"===typeof module&&module.exports?module.exports=k():"function"===typeof define&&define.amd?define(k):g.SecondLevelDomains=k(g)})(this,function(g){var k=g&&g.SecondLevelDomains,h={list:{ac:" com gov mil net org ",ae:" ac co gov mil name net org pro sch ",af:" com edu gov net org ",al:" com edu gov mil net org ",ao:" co ed gv it og pb ",ar:" com edu gob gov int mil net org tur ",at:" ac co gv or ",au:" asn com csiro edu gov id net org ",ba:" co com edu gov mil net org rs unbi unmo unsa untz unze ", bb:" biz co com edu gov info net org store tv ",bh:" biz cc com edu gov info net org ",bn:" com edu gov net org ",bo:" com edu gob gov int mil net org tv ",br:" adm adv agr am arq art ato b bio blog bmd cim cng cnt com coop ecn edu eng esp etc eti far flog fm fnd fot fst g12 ggf gov imb ind inf jor jus lel mat med mil mus net nom not ntr odo org ppg pro psc psi qsl rec slg srv tmp trd tur tv vet vlog wiki zlg ",bs:" com edu gov net org ",bz:" du et om ov rg ",ca:" ab bc mb nb nf nl ns nt nu on pe qc sk yk ", ck:" biz co edu gen gov info net org ",cn:" ac ah bj com cq edu fj gd gov gs gx gz ha hb he hi hl hn jl js jx ln mil net nm nx org qh sc sd sh sn sx tj tw xj xz yn zj ",co:" com edu gov mil net nom org ",cr:" ac c co ed fi go or sa ",cy:" ac biz com ekloges gov ltd name net org parliament press pro tm ","do":" art com edu gob gov mil net org sld web ",dz:" art asso com edu gov net org pol ",ec:" com edu fin gov info med mil net org pro ",eg:" com edu eun gov mil name net org sci ",er:" com edu gov ind mil net org rochest w ", es:" com edu gob nom org ",et:" biz com edu gov info name net org ",fj:" ac biz com info mil name net org pro ",fk:" ac co gov net nom org ",fr:" asso com f gouv nom prd presse tm ",gg:" co net org ",gh:" com edu gov mil org ",gn:" ac com gov net org ",gr:" com edu gov mil net org ",gt:" com edu gob ind mil net org ",gu:" com edu gov net org ",hk:" com edu gov idv net org ",hu:" 2000 agrar bolt casino city co erotica erotika film forum games hotel info ingatlan jogasz konyvelo lakas media news org priv reklam sex shop sport suli szex tm tozsde utazas video ", @@ -20,71 +20,71 @@ ps:" com edu gov net org plo sec ",pw:" belau co ed go ne or ",ro:" arts com fir tw:" club com ebiz edu game gov idv mil net org ",mu:" ac co com gov net or org ",mz:" ac co edu gov org ",na:" co com ",nz:" ac co cri geek gen govt health iwi maori mil net org parliament school ",pa:" abo ac com edu gob ing med net nom org sld ",pt:" com edu gov int net nome org publ ",py:" com edu gov mil net org ",qa:" com edu gov mil net org ",re:" asso com nom ",ru:" ac adygeya altai amur arkhangelsk astrakhan bashkiria belgorod bir bryansk buryatia cbg chel chelyabinsk chita chukotka chuvashia com dagestan e-burg edu gov grozny int irkutsk ivanovo izhevsk jar joshkar-ola kalmykia kaluga kamchatka karelia kazan kchr kemerovo khabarovsk khakassia khv kirov koenig komi kostroma kranoyarsk kuban kurgan kursk lipetsk magadan mari mari-el marine mil mordovia mosreg msk murmansk nalchik net nnov nov novosibirsk nsk omsk orenburg org oryol penza perm pp pskov ptz rnd ryazan sakhalin samara saratov simbirsk smolensk spb stavropol stv surgut tambov tatarstan tom tomsk tsaritsyn tsk tula tuva tver tyumen udm udmurtia ulan-ude vladikavkaz vladimir vladivostok volgograd vologda voronezh vrn vyatka yakutia yamal yekaterinburg yuzhno-sakhalinsk ", rw:" ac co com edu gouv gov int mil net ",sa:" com edu gov med net org pub sch ",sd:" com edu gov info med net org tv ",se:" a ac b bd c d e f g h i k l m n o org p parti pp press r s t tm u w x y z ",sg:" com edu gov idn net org per ",sn:" art com edu gouv org perso univ ",sy:" com edu gov mil net news org ",th:" ac co go in mi net or ",tj:" ac biz co com edu go gov info int mil name net nic org test web ",tn:" agrinet com defense edunet ens fin gov ind info intl mincom nat net org perso rnrt rns rnu tourism ", tz:" ac co go ne or ",ua:" biz cherkassy chernigov chernovtsy ck cn co com crimea cv dn dnepropetrovsk donetsk dp edu gov if in ivano-frankivsk kh kharkov kherson khmelnitskiy kiev kirovograd km kr ks kv lg lugansk lutsk lviv me mk net nikolaev od odessa org pl poltava pp rovno rv sebastopol sumy te ternopil uzhgorod vinnica vn zaporizhzhe zhitomir zp zt ",ug:" ac co go ne or org sc ",uk:" ac bl british-library co cym gov govt icnet jet lea ltd me mil mod national-library-scotland nel net nhs nic nls org orgn parliament plc police sch scot soc ", -us:" dni fed isa kids nsn ",uy:" com edu gub mil net org ",ve:" co com edu gob info mil net org web ",vi:" co com k12 net org ",vn:" ac biz com edu gov health info int name net org pro ",ye:" co com gov ltd me net org plc ",yu:" ac co edu gov org ",za:" ac agric alt bourse city co cybernet db edu gov grondar iaccess imt inca landesign law mil net ngo nis nom olivetti org pix school tm web ",zm:" ac co com edu gov net org sch "},has:function(f){var b=f.lastIndexOf(".");if(0>=b||b>=f.length-1)return!1; -var k=f.lastIndexOf(".",b-1);if(0>=k||k>=b-1)return!1;var m=g.list[f.slice(b+1)];return m?0<=m.indexOf(" "+f.slice(k+1,b)+" "):!1},is:function(f){var b=f.lastIndexOf(".");if(0>=b||b>=f.length-1||0<=f.lastIndexOf(".",b-1))return!1;var k=g.list[f.slice(b+1)];return k?0<=k.indexOf(" "+f.slice(0,b)+" "):!1},get:function(f){var b=f.lastIndexOf(".");if(0>=b||b>=f.length-1)return null;var k=f.lastIndexOf(".",b-1);if(0>=k||k>=b-1)return null;var m=g.list[f.slice(b+1)];return!m||0>m.indexOf(" "+f.slice(k+ -1,b)+" ")?null:f.slice(k+1)},noConflict:function(){f.SecondLevelDomains===this&&(f.SecondLevelDomains=m);return this}};return g}); -(function(f,m){"object"===typeof module&&module.exports?module.exports=m(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"===typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],m):f.URI=m(f.punycode,f.IPv6,f.SecondLevelDomains,f)})(this,function(f,m,g,k){function b(a,c){var d=1<=arguments.length,n=2<=arguments.length;if(!(this instanceof b))return d?n?new b(a,c):new b(a):new b;if(void 0===a){if(d)throw new TypeError("undefined is not a valid argument for URI"); -a="undefined"!==typeof location?location.href+"":""}if(null===a&&d)throw new TypeError("null is not a valid argument for URI");this.href(a);return void 0!==c?this.absoluteTo(c):this}function l(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function A(a){return void 0===a?"Undefined":String(Object.prototype.toString.call(a)).slice(8,-1)}function v(a){return"Array"===A(a)}function h(a,c){var d={},b,t;if("RegExp"===A(c))d=null;else if(v(c))for(b=0,t=c.length;b=b||b>=g.length-1)return!1; +var l=g.lastIndexOf(".",b-1);if(0>=l||l>=b-1)return!1;var k=h.list[g.slice(b+1)];return k?0<=k.indexOf(" "+g.slice(l+1,b)+" "):!1},is:function(g){var b=g.lastIndexOf(".");if(0>=b||b>=g.length-1||0<=g.lastIndexOf(".",b-1))return!1;var l=h.list[g.slice(b+1)];return l?0<=l.indexOf(" "+g.slice(0,b)+" "):!1},get:function(g){var b=g.lastIndexOf(".");if(0>=b||b>=g.length-1)return null;var l=g.lastIndexOf(".",b-1);if(0>=l||l>=b-1)return null;var k=h.list[g.slice(b+1)];return!k||0>k.indexOf(" "+g.slice(l+ +1,b)+" ")?null:g.slice(l+1)},noConflict:function(){g.SecondLevelDomains===this&&(g.SecondLevelDomains=k);return this}};return h}); +(function(g,k){"object"===typeof module&&module.exports?module.exports=k(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"===typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],k):g.URI=k(g.punycode,g.IPv6,g.SecondLevelDomains,g)})(this,function(g,k,h,l){function b(a,c){var d=1<=arguments.length,p=2<=arguments.length;if(!(this instanceof b))return d?p?new b(a,c):new b(a):new b;if(void 0===a){if(d)throw new TypeError("undefined is not a valid argument for URI"); +a="undefined"!==typeof location?location.href+"":""}if(null===a&&d)throw new TypeError("null is not a valid argument for URI");this.href(a);return void 0!==c?this.absoluteTo(c):this}function m(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function A(a){return void 0===a?"Undefined":String(Object.prototype.toString.call(a)).slice(8,-1)}function u(a){return"Array"===A(a)}function f(a,c){var d={},b,t;if("RegExp"===A(c))d=null;else if(u(c))for(b=0,t=c.length;b]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u2018\u2019]))/ig;b.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u201e\u2018\u2019]+$/,parens:/(\([^\)]*\)|\[[^\]]*\]|\{[^}]*\}|<[^>]*>)/g};b.defaultPorts={http:"80",https:"443",ftp:"21", -gopher:"70",ws:"80",wss:"443"};b.invalid_hostname_characters=/[^a-zA-Z0-9\.-]/;b.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src",audio:"src",video:"src"};b.getDomAttribute=function(a){if(a&&a.nodeName){var c=a.nodeName.toLowerCase();if("input"!==c||"image"===a.type)return b.domAttributes[c]}};b.encode=x;b.decode=decodeURIComponent;b.iso8859=function(){b.encode=escape;b.decode= -unescape};b.unicode=function(){b.encode=x;b.decode=decodeURIComponent};b.characters={pathname:{encode:{expression:/%(24|26|2B|2C|3B|3D|3A|40)/ig,map:{"%24":"$","%26":"&","%2B":"+","%2C":",","%3B":";","%3D":"=","%3A":":","%40":"@"}},decode:{expression:/[\/\?#]/g,map:{"/":"%2F","?":"%3F","#":"%23"}}},reserved:{encode:{expression:/%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/ig,map:{"%3A":":","%2F":"/","%3F":"?","%23":"#","%5B":"[","%5D":"]","%40":"@","%21":"!","%24":"$","%26":"&","%27":"'", +gopher:"70",ws:"80",wss:"443"};b.invalid_hostname_characters=/[^a-zA-Z0-9\.-]/;b.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src",audio:"src",video:"src"};b.getDomAttribute=function(a){if(a&&a.nodeName){var c=a.nodeName.toLowerCase();if("input"!==c||"image"===a.type)return b.domAttributes[c]}};b.encode=y;b.decode=decodeURIComponent;b.iso8859=function(){b.encode=escape;b.decode= +unescape};b.unicode=function(){b.encode=y;b.decode=decodeURIComponent};b.characters={pathname:{encode:{expression:/%(24|26|2B|2C|3B|3D|3A|40)/ig,map:{"%24":"$","%26":"&","%2B":"+","%2C":",","%3B":";","%3D":"=","%3A":":","%40":"@"}},decode:{expression:/[\/\?#]/g,map:{"/":"%2F","?":"%3F","#":"%23"}}},reserved:{encode:{expression:/%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/ig,map:{"%3A":":","%2F":"/","%3F":"?","%23":"#","%5B":"[","%5D":"]","%40":"@","%21":"!","%24":"$","%26":"&","%27":"'", "%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"="}}},urnpath:{encode:{expression:/%(21|24|27|28|29|2A|2B|2C|3B|3D|40)/ig,map:{"%21":"!","%24":"$","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"=","%40":"@"}},decode:{expression:/[\/\?#:]/g,map:{"/":"%2F","?":"%3F","#":"%23",":":"%3A"}}}};b.encodeQuery=function(a,c){var d=b.encode(a+"");void 0===c&&(c=b.escapeQuerySpace);return c?d.replace(/%20/g,"+"):d};b.decodeQuery=function(a,c){a+="";void 0===c&& -(c=b.escapeQuerySpace);try{return b.decode(c?a.replace(/\+/g,"%20"):a)}catch(d){return a}};var r={encode:"encode",decode:"decode"},B,F=function(a,c){return function(d){try{return b[c](d+"").replace(b.characters[a][c].expression,function(d){return b.characters[a][c].map[d]})}catch(n){return d}}};for(B in r)b[B+"PathSegment"]=F("pathname",r[B]),b[B+"UrnPathSegment"]=F("urnpath",r[B]);r=function(a,c,d){return function(n){var t;t=d?function(a){return b[c](b[d](a))}:b[c];n=(n+"").split(a);for(var e=0, -f=n.length;eb)return a.charAt(0)===c.charAt(0)&&"/"===a.charAt(0)?"/":"";if("/"!==a.charAt(b)||"/"!==c.charAt(b))b=a.substring(0,b).lastIndexOf("/");return a.substring(0,b+1)};b.withinString=function(a,c,d){d||(d={}); -var e=d.start||b.findUri.start,f=d.end||b.findUri.end,h=d.trim||b.findUri.trim,g=d.parens||b.findUri.parens,q=/[a-z0-9-]=["']?$/i;for(e.lastIndex=0;;){var k=e.exec(a);if(!k)break;var m=k.index;if(d.ignoreHtml){var p=a.slice(Math.max(m-3,0),m);if(p&&q.test(p))continue}for(var l=m+a.slice(m).search(f),p=a.slice(m,l),l=-1;;){var z=g.exec(p);if(!z)break;l=Math.max(l,z.index+z[0].length)}p=-1d.length)return this._parts.hostname;d=this._parts.hostname.length-this.tld(c).length-1;d=this._parts.hostname.lastIndexOf(".",d-1)+1;return this._parts.hostname.substring(d)||""}if(!a)throw new TypeError("cannot set domain empty");b.ensureValidHostname(a); -!this._parts.hostname||this.is("IP")?this._parts.hostname=a:(d=new RegExp(l(this.domain())+"$"),this._parts.hostname=this._parts.hostname.replace(d,a));this.build(!c);return this};e.tld=function(a,c){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(c=a,a=void 0);if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var d=this._parts.hostname.lastIndexOf("."),d=this._parts.hostname.substring(d+1);return!0!==c&&g&&g.list[d.toLowerCase()]?g.get(this._parts.hostname)||d:d}if(a)if(a.match(/[^a-zA-Z0-9-]/))if(g&& -g.is(a))d=new RegExp(l(this.tld())+"$"),this._parts.hostname=this._parts.hostname.replace(d,a);else throw new TypeError('TLD "'+a+'" contains characters other than [A-Z0-9]');else{if(!this._parts.hostname||this.is("IP"))throw new ReferenceError("cannot set TLD on non-domain host");d=new RegExp(l(this.tld())+"$");this._parts.hostname=this._parts.hostname.replace(d,a)}else throw new TypeError("cannot set TLD empty");this.build(!c);return this};e.directory=function(a,c){if(this._parts.urn)return void 0=== -a?"":this;if(void 0===a||!0===a){if(!this._parts.path&&!this._parts.hostname)return"";if("/"===this._parts.path)return"/";var d=this._parts.path.length-this.filename().length-1,d=this._parts.path.substring(0,d)||(this._parts.hostname?"/":"");return a?b.decodePath(d):d}d=this._parts.path.length-this.filename().length;d=this._parts.path.substring(0,d);d=new RegExp("^"+l(d));this.is("relative")||(a||(a="/"),"/"!==a.charAt(0)&&(a="/"+a));a&&"/"!==a.charAt(a.length-1)&&(a+="/");a=b.recodePath(a);this._parts.path= -this._parts.path.replace(d,a);this.build(!c);return this};e.filename=function(a,c){if(this._parts.urn)return void 0===a?"":this;if("string"!==typeof a){if(!this._parts.path||"/"===this._parts.path)return"";var d=this._parts.path.lastIndexOf("/"),d=this._parts.path.substring(d+1);return a?b.decodePathSegment(d):d}d=!1;"/"===a.charAt(0)&&(a=a.substring(1));a.match(/\.?\//)&&(d=!0);var e=new RegExp(l(this.filename())+"$");a=b.recodePath(a);this._parts.path=this._parts.path.replace(e,a);d?this.normalizePath(c): -this.build(!c);return this};e.suffix=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path||"/"===this._parts.path)return"";var d=this.filename(),e=d.lastIndexOf(".");if(-1===e)return"";d=d.substring(e+1);d=/^[a-z0-9%]+$/i.test(d)?d:"";return a?b.decodePathSegment(d):d}"."===a.charAt(0)&&(a=a.substring(1));if(d=this.suffix())e=a?new RegExp(l(d)+"$"):new RegExp(l("."+d)+"$");else{if(!a)return this;this._parts.path+="."+b.recodePath(a)}e&&(a=b.recodePath(a), -this._parts.path=this._parts.path.replace(e,a));this.build(!c);return this};e.segment=function(a,c,d){var b=this._parts.urn?":":"/",e=this.path(),f="/"===e.substring(0,1),e=e.split(b);void 0!==a&&"number"!==typeof a&&(d=c,c=a,a=void 0);if(void 0!==a&&"number"!==typeof a)throw Error('Bad segment "'+a+'", must be 0-based integer');f&&e.shift();0>a&&(a=Math.max(e.length+a,0));if(void 0===c)return void 0===a?e:e[a];if(null===a||void 0===e[a])if(v(c)){e=[];a=0;for(var h=c.length;aa&&(a=Math.max(e.length+a,0));if(void 0===c)return void 0===a?e:e[a];if(null===a||void 0===e[a])if(u(c)){e=[];a=0;for(var g=c.length;a{}"`^| \\]/;g.expand=function(b,f){var h=v[b.operator],k=h.named?"Named":"Unnamed",m=b.variables,q=[],l,y,u;for(u=0;y=m[u];u++)if(l=f.get(y.name),l.val.length){if(1{}"`^| \\]/;h.expand=function(b,g,l){var f=u[b.operator],n=f.named?"Named":"Unnamed";b=b.variables;var k=[],m,x,v;for(v=0;x=b[v];v++){m=g.get(x.name);if(0===m.type&&l&&l.strict)throw Error('Missing expansion value for variable "'+ +x.name+'"');if(m.val.length){if(1 Date: Thu, 30 Mar 2017 10:52:50 +0200 Subject: [PATCH 19/44] fix(SLD): adding CentralNic SLDs - #333 --- CHANGELOG.md | 4 +++ src/SecondLevelDomains.js | 7 ++++- test/test.js | 62 ++++++++++++++++++++++++--------------- 3 files changed, 49 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b545990..f8cfd7be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ The release notes tracked in this document are also made available on the [releases page](https://github.com/medialize/URI.js/releases) +### master ### + +* adding support for [CentralNic](https://en.wikipedia.org/wiki/CentralNic#Second-level_domains) Second Level Domains - [Issue #333](https://github.com/medialize/URI.js/issues/333) + ### 1.18.9 (March 6th 2017) ### * adding option `strict` to [`URITemplate()`](http://medialize.github.io/URI.js/uri-template.html) in order to throw an exception in case a placeholder could not be replaced - [PR #330](https://github.com/medialize/URI.js/issues/330) diff --git a/src/SecondLevelDomains.js b/src/SecondLevelDomains.js index ac9e3e62..aaea484c 100644 --- a/src/SecondLevelDomains.js +++ b/src/SecondLevelDomains.js @@ -173,7 +173,12 @@ 'ye':' co com gov ltd me net org plc ', 'yu':' ac co edu gov org ', 'za':' ac agric alt bourse city co cybernet db edu gov grondar iaccess imt inca landesign law mil net ngo nis nom olivetti org pix school tm web ', - 'zm':' ac co com edu gov net org sch ' + 'zm':' ac co com edu gov net org sch ', + // https://en.wikipedia.org/wiki/CentralNic#Second-level_domains + 'com': 'ar br cn de eu gb gr hu jpn kr no qc ru sa se uk us uy za ', + 'net': 'gb jp se uk ', + 'org': 'ae', + 'de': 'com ' }, // gorhill 2013-10-25: Using indexOf() instead Regexp(). Significant boost // in both performance and memory footprint. No initialization required. diff --git a/test/test.js b/test/test.js index dc07acf0..1cc2ce5d 100644 --- a/test/test.js +++ b/test/test.js @@ -560,29 +560,20 @@ }); test('sld', function() { - // Lets just test them all.. - // Calling URI.is(), URI.domain(), URI.subdomain() allows us to indirectly - // test SLD.has(), SLD.is() and SLD.get() - var u = new URI('http://www.example.org/foo.html'); - equal(u.is('sld'), false, 'is not sld'); - var list = SecondLevelDomains.list; - var tlds = Object.keys(list); - var iTld = tlds.length; - var tld, slds, sld, iSld; - while ( iTld-- ) { - tld = tlds[iTld]; - slds = list[tld].trim().split(/\s+/); - iSld = slds.length; - while ( iSld-- ) { - sld = slds[iSld].trim() + '.' + tld; - u.hostname('www.example.' + sld); - equal(u.is('sld'), true, 'is sld'); - equal(u.domain(), 'example.' + sld, 'domain is example.' + sld); - equal(u.subdomain(), 'www', 'subdomain is www'); - u.hostname('www.example.' + tld); - equal(u.is('sld'), false, 'is not sld'); - } - } + var u = new URI('http://www.example.ch/foo.html') + equal(u.is('sld'), false, 'is() www.example.ch'); + equal(u.domain(), 'example.ch', 'domain() www.example.ch'); + equal(u.subdomain(), 'www', 'subdomain() www.example.ch'); + + u = new URI('http://www.example.com/foo.html') + equal(u.is('sld'), false, 'is() www.example.com'); + equal(u.domain(), 'example.com', 'domain() www.example.com'); + equal(u.subdomain(), 'www', 'subdomain() www.example.com'); + + u = new URI('http://www.example.eu.com/foo.html') + equal(u.is('sld'), true, 'is() www.example.eu.com'); + equal(u.domain(), 'example.eu.com', 'domain() www.example.eu.com'); + equal(u.subdomain(), 'www', 'subdomain() www.example.eu.com'); }); test('directory', function() { var u = new URI('http://www.example.org/some/directory/foo.html'); @@ -1855,4 +1846,29 @@ equal(URI.encodeReserved('ä:/?#[]@!$&\'()*+,;='), '%C3%A4:/?#[]@!$&\'()*+,;='); }); + module('SecondLevelDomains'); + test('SecondLevelDomains.get()', function() { + equal(SecondLevelDomains.get('www.example.ch'), null, 'www.example.ch') + equal(SecondLevelDomains.get('www.example.com'), null, 'www.example.com') + equal(SecondLevelDomains.get('www.example.eu.com'), 'eu.com', 'www.example.eu.com') + equal(SecondLevelDomains.get('www.example.co.uk'), 'co.uk', 'www.example.co.uk') + }); + test('SecondLevelDomains.has()', function() { + equal(SecondLevelDomains.has('www.example.ch'), false, 'www.example.ch') + equal(SecondLevelDomains.has('www.example.com'), false, 'www.example.com') + equal(SecondLevelDomains.has('www.example.eu.com'), true, 'www.example.eu.com') + equal(SecondLevelDomains.has('www.example.co.uk'), true, 'www.example.co.uk') + }); + test('SecondLevelDomains.is()', function() { + equal(SecondLevelDomains.is('ch'), false, 'ch') + equal(SecondLevelDomains.is('example.ch'), false, 'example.ch') + + equal(SecondLevelDomains.is('com'), false, 'com') + equal(SecondLevelDomains.is('eu.com'), true, 'eu.com') + equal(SecondLevelDomains.is('example.com'), false, 'example.com') + + equal(SecondLevelDomains.is('uk'), false, 'uk') + equal(SecondLevelDomains.is('co.uk'), true, 'co.uk') + }); + })(); From 8a3e8e6cca8e150e8e5f572e6bf2d35cf0bef3b2 Mon Sep 17 00:00:00 2001 From: Rodney Rehm Date: Thu, 30 Mar 2017 10:54:57 +0200 Subject: [PATCH 20/44] chore(build): bumping to version 1.18.10 --- CHANGELOG.md | 2 +- bower.json | 2 +- build.js | 2 +- package.json | 2 +- src/IPv6.js | 2 +- src/SecondLevelDomains.js | 2 +- src/URI.js | 4 ++-- src/URITemplate.js | 2 +- src/jquery.URI.js | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8cfd7be..0d0b55ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ The release notes tracked in this document are also made available on the [releases page](https://github.com/medialize/URI.js/releases) -### master ### +### 1.18.10 (March 30th 2017) ### * adding support for [CentralNic](https://en.wikipedia.org/wiki/CentralNic#Second-level_domains) Second Level Domains - [Issue #333](https://github.com/medialize/URI.js/issues/333) diff --git a/bower.json b/bower.json index 6e11cc36..7f5e5572 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "urijs", - "version": "1.18.9", + "version": "1.18.10", "main": "src/URI.js", "ignore": [ ".*", diff --git a/build.js b/build.js index f9158f99..64c7c785 100644 --- a/build.js +++ b/build.js @@ -29,7 +29,7 @@ function build(files) { output_format: "text", output_info: "compiled_code" }, function(data) { - var code = "/*! URI.js v1.18.9 http://medialize.github.io/URI.js/ */\n/* build contains: " + files.join(', ') + " */\n" + data; + var code = "/*! URI.js v1.18.10 http://medialize.github.io/URI.js/ */\n/* build contains: " + files.join(', ') + " */\n" + data; $progress.hide(); $out.val(code).parent().show(); $out.prev().find('a').remove(); diff --git a/package.json b/package.json index fefdd1c7..5fccb719 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "urijs", - "version": "1.18.9", + "version": "1.18.10", "title": "URI.js - Mutating URLs", "author": { "name": "Rodney Rehm", diff --git a/src/IPv6.js b/src/IPv6.js index 7f1b7c9e..3e98053c 100644 --- a/src/IPv6.js +++ b/src/IPv6.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * IPv6 Support * - * Version: 1.18.9 + * Version: 1.18.10 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/SecondLevelDomains.js b/src/SecondLevelDomains.js index aaea484c..3363d12e 100644 --- a/src/SecondLevelDomains.js +++ b/src/SecondLevelDomains.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * Second Level Domain (SLD) Support * - * Version: 1.18.9 + * Version: 1.18.10 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/URI.js b/src/URI.js index bc96cf07..6f7fd572 100644 --- a/src/URI.js +++ b/src/URI.js @@ -1,7 +1,7 @@ /*! * URI.js - Mutating URLs * - * Version: 1.18.9 + * Version: 1.18.10 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ @@ -77,7 +77,7 @@ return this; } - URI.version = '1.18.9'; + URI.version = '1.18.10'; var p = URI.prototype; var hasOwn = Object.prototype.hasOwnProperty; diff --git a/src/URITemplate.js b/src/URITemplate.js index 4a25a9d5..eaeb8cc0 100644 --- a/src/URITemplate.js +++ b/src/URITemplate.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * URI Template Support - http://tools.ietf.org/html/rfc6570 * - * Version: 1.18.9 + * Version: 1.18.10 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/jquery.URI.js b/src/jquery.URI.js index 7d87fef3..307c4b4e 100644 --- a/src/jquery.URI.js +++ b/src/jquery.URI.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * jQuery Plugin * - * Version: 1.18.9 + * Version: 1.18.10 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/jquery-uri-plugin.html From d6f596ce5dd463289ddd0ecf994503461b5f1894 Mon Sep 17 00:00:00 2001 From: Rodney Rehm Date: Thu, 30 Mar 2017 10:59:32 +0200 Subject: [PATCH 21/44] chore(dist): updating distributables to version 1.18.10 --- src/URI.min.js | 10 +++++----- src/jquery.URI.min.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/URI.min.js b/src/URI.min.js index d24a5371..9c66b0f9 100644 --- a/src/URI.min.js +++ b/src/URI.min.js @@ -1,4 +1,4 @@ -/*! URI.js v1.18.9 http://medialize.github.io/URI.js/ */ +/*! URI.js v1.18.10 http://medialize.github.io/URI.js/ */ /* build contains: IPv6.js, punycode.js, SecondLevelDomains.js, URI.js, URITemplate.js */ (function(g,k){"object"===typeof module&&module.exports?module.exports=k():"function"===typeof define&&define.amd?define(k):g.IPv6=k(g)})(this,function(g){var k=g&&g.IPv6;return{best:function(h){h=h.toLowerCase().split(":");var l=h.length,b=8;""===h[0]&&""===h[1]&&""===h[2]?(h.shift(),h.shift()):""===h[0]&&""===h[1]?h.shift():""===h[l-1]&&""===h[l-2]&&h.pop();l=h.length;-1!==h[l-1].indexOf(".")&&(b=7);var m;for(m=0;mg;g++)if("0"===l[0]&&1g&&(l=f,g=k)):"0"===h[m]&&(n=!0,f=m,k=1);k>g&&(l=f,g=k);1=b||b>=g.length-1)return!1; -var l=g.lastIndexOf(".",b-1);if(0>=l||l>=b-1)return!1;var k=h.list[g.slice(b+1)];return k?0<=k.indexOf(" "+g.slice(l+1,b)+" "):!1},is:function(g){var b=g.lastIndexOf(".");if(0>=b||b>=g.length-1||0<=g.lastIndexOf(".",b-1))return!1;var l=h.list[g.slice(b+1)];return l?0<=l.indexOf(" "+g.slice(0,b)+" "):!1},get:function(g){var b=g.lastIndexOf(".");if(0>=b||b>=g.length-1)return null;var l=g.lastIndexOf(".",b-1);if(0>=l||l>=b-1)return null;var k=h.list[g.slice(b+1)];return!k||0>k.indexOf(" "+g.slice(l+ -1,b)+" ")?null:g.slice(l+1)},noConflict:function(){g.SecondLevelDomains===this&&(g.SecondLevelDomains=k);return this}};return h}); +us:" dni fed isa kids nsn ",uy:" com edu gub mil net org ",ve:" co com edu gob info mil net org web ",vi:" co com k12 net org ",vn:" ac biz com edu gov health info int name net org pro ",ye:" co com gov ltd me net org plc ",yu:" ac co edu gov org ",za:" ac agric alt bourse city co cybernet db edu gov grondar iaccess imt inca landesign law mil net ngo nis nom olivetti org pix school tm web ",zm:" ac co com edu gov net org sch ",com:"ar br cn de eu gb gr hu jpn kr no qc ru sa se uk us uy za ",net:"gb jp se uk ", +org:"ae",de:"com "},has:function(g){var b=g.lastIndexOf(".");if(0>=b||b>=g.length-1)return!1;var l=g.lastIndexOf(".",b-1);if(0>=l||l>=b-1)return!1;var k=h.list[g.slice(b+1)];return k?0<=k.indexOf(" "+g.slice(l+1,b)+" "):!1},is:function(g){var b=g.lastIndexOf(".");if(0>=b||b>=g.length-1||0<=g.lastIndexOf(".",b-1))return!1;var l=h.list[g.slice(b+1)];return l?0<=l.indexOf(" "+g.slice(0,b)+" "):!1},get:function(g){var b=g.lastIndexOf(".");if(0>=b||b>=g.length-1)return null;var l=g.lastIndexOf(".",b-1); +if(0>=l||l>=b-1)return null;var k=h.list[g.slice(b+1)];return!k||0>k.indexOf(" "+g.slice(l+1,b)+" ")?null:g.slice(l+1)},noConflict:function(){g.SecondLevelDomains===this&&(g.SecondLevelDomains=k);return this}};return h}); (function(g,k){"object"===typeof module&&module.exports?module.exports=k(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"===typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],k):g.URI=k(g.punycode,g.IPv6,g.SecondLevelDomains,g)})(this,function(g,k,h,l){function b(a,c){var d=1<=arguments.length,p=2<=arguments.length;if(!(this instanceof b))return d?p?new b(a,c):new b(a):new b;if(void 0===a){if(d)throw new TypeError("undefined is not a valid argument for URI"); a="undefined"!==typeof location?location.href+"":""}if(null===a&&d)throw new TypeError("null is not a valid argument for URI");this.href(a);return void 0!==c?this.absoluteTo(c):this}function m(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function A(a){return void 0===a?"Undefined":String(Object.prototype.toString.call(a)).slice(8,-1)}function u(a){return"Array"===A(a)}function f(a,c){var d={},b,t;if("RegExp"===A(c))d=null;else if(u(c))for(b=0,t=c.length;b]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u2018\u2019]))/ig;b.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u201e\u2018\u2019]+$/,parens:/(\([^\)]*\)|\[[^\]]*\]|\{[^}]*\}|<[^>]*>)/g};b.defaultPorts={http:"80",https:"443",ftp:"21", gopher:"70",ws:"80",wss:"443"};b.invalid_hostname_characters=/[^a-zA-Z0-9\.-]/;b.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src",audio:"src",video:"src"};b.getDomAttribute=function(a){if(a&&a.nodeName){var c=a.nodeName.toLowerCase();if("input"!==c||"image"===a.type)return b.domAttributes[c]}};b.encode=y;b.decode=decodeURIComponent;b.iso8859=function(){b.encode=escape;b.decode= diff --git a/src/jquery.URI.min.js b/src/jquery.URI.min.js index ae65585f..f5d26910 100644 --- a/src/jquery.URI.min.js +++ b/src/jquery.URI.min.js @@ -1,4 +1,4 @@ -/*! URI.js v1.18.9 http://medialize.github.io/URI.js/ */ +/*! URI.js v1.18.10 http://medialize.github.io/URI.js/ */ /* build contains: jquery.URI.js */ (function(d,e){"object"===typeof module&&module.exports?module.exports=e(require("jquery"),require("./URI")):"function"===typeof define&&define.amd?define(["jquery","./URI"],e):e(d.jQuery,d.URI)})(this,function(d,e){function h(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function k(a){var b=a.nodeName.toLowerCase();if("input"!==b||"image"===a.type)return e.domAttributes[b]}function p(a){return{get:function(b){return d(b).uri()[a]()},set:function(b,c){d(b).uri()[a](c);return c}}}function l(a, b){var c,e,f;if(!k(a)||!b)return!1;c=b.match(q);if(!c||!c[5]&&":"!==c[2]&&!g[c[2]])return!1;f=d(a).uri();if(c[5])return f.is(c[5]);if(":"===c[2])return e=c[1].toLowerCase()+":",g[e]?g[e](f,c[4]):!1;e=c[1].toLowerCase();return m[e]?g[c[2]](f[e](),c[4],e):!1}var m={},g={"=":function(a,b){return a===b},"^=":function(a,b){return!!(a+"").match(new RegExp("^"+h(b),"i"))},"$=":function(a,b){return!!(a+"").match(new RegExp(h(b)+"$","i"))},"*=":function(a,b,c){"directory"===c&&(a+="/");return!!(a+"").match(new RegExp(h(b), From 772852f1955f64a4694318c8d250d5b40d039202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Bl=C3=A4si?= Date: Tue, 8 Aug 2017 22:51:39 +0200 Subject: [PATCH 22/44] fix(parse): throw on invalid input (#345) validate hostname and port --- src/URI.js | 61 +++++++++++++++++++++++++++++++++++++++++++--------- test/test.js | 36 +++++++++++++++++++++++-------- 2 files changed, 78 insertions(+), 19 deletions(-) diff --git a/src/URI.js b/src/URI.js index 6f7fd572..f63ad6c6 100644 --- a/src/URI.js +++ b/src/URI.js @@ -240,10 +240,16 @@ ws: '80', wss: '443' }; + // list of protocols which always require a hostname + URI.hostProtocols = [ + 'http', + 'https' + ]; + // allowed hostname characters according to RFC 3986 // ALPHA DIGIT "-" "." "_" "~" "!" "$" "&" "'" "(" ")" "*" "+" "," ";" "=" %encoded // I've never seen a (non-IDN) hostname other than: ALPHA DIGIT . - - URI.invalid_hostname_characters = /[^a-zA-Z0-9\.-]/; + URI.invalid_hostname_characters = /[^a-zA-Z0-9\.\-:]/; // map DOM Elements to their URI attribute URI.domAttributes = { 'a': 'href', @@ -575,6 +581,12 @@ string = '/' + string; } + URI.ensureValidHostname(parts.hostname, parts.protocol); + + if (parts.port) { + URI.ensureValidPort(parts.port); + } + return string.substring(pos) || '/'; }; URI.parseAuthority = function(string, parts) { @@ -1015,22 +1027,44 @@ return string; }; - URI.ensureValidHostname = function(v) { + URI.ensureValidHostname = function(v, protocol) { // Theoretically URIs allow percent-encoding in Hostnames (according to RFC 3986) // they are not part of DNS and therefore ignored by URI.js - if (v.match(URI.invalid_hostname_characters)) { + var hasHostname = !!v; // not null and not an empty string + var hasProtocol = !!protocol; + var rejectEmptyHostname = false; + + if (hasProtocol) { + rejectEmptyHostname = arrayContains(URI.hostProtocols, protocol); + } + + if (rejectEmptyHostname && !hasHostname) { + throw new TypeError('Hostname cannot be empty, if protocol is ' + protocol); + } else if (v && v.match(URI.invalid_hostname_characters)) { // test punycode if (!punycode) { throw new TypeError('Hostname "' + v + '" contains characters other than [A-Z0-9.-] and Punycode.js is not available'); } - if (punycode.toASCII(v).match(URI.invalid_hostname_characters)) { - throw new TypeError('Hostname "' + v + '" contains characters other than [A-Z0-9.-]'); + throw new TypeError('Hostname "' + v + '" contains characters other than [A-Z0-9.:-]'); } } }; + URI.ensureValidPort = function (v) { + if (!v) { + return; + } + + var port = Number(v); + if (Number.isInteger(port) && (port > 0) && (port < 65536)) { + return; + } + + throw new TypeError('Port "' + v + '" is not a valid port'); + }; + // noConflict URI.noConflict = function(removeAll) { if (removeAll) { @@ -1288,9 +1322,7 @@ v = v.substring(1); } - if (v.match(/[^0-9]/)) { - throw new TypeError('Port "' + v + '" contains characters other than [0-9]'); - } + URI.ensureValidPort(v); } } return _port.call(this, v, build); @@ -1308,6 +1340,7 @@ } v = x.hostname; + URI.ensureValidHostname(v, this._parts.protocol); } return _hostname.call(this, v, build); }; @@ -1426,8 +1459,12 @@ v += '.'; } + if (v.indexOf(':') !== -1) { + throw new TypeError('Domains cannot contain colons'); + } + if (v) { - URI.ensureValidHostname(v); + URI.ensureValidHostname(v, this._parts.protocol); } this._parts.hostname = this._parts.hostname.replace(replace, v); @@ -1466,7 +1503,11 @@ throw new TypeError('cannot set domain empty'); } - URI.ensureValidHostname(v); + if (v.indexOf(':') !== -1) { + throw new TypeError('Domains cannot contain colons'); + } + + URI.ensureValidHostname(v, this._parts.protocol); if (!this._parts.hostname || this.is('IP')) { this._parts.hostname = v; diff --git a/test/test.js b/test/test.js index 1cc2ce5d..8ebf8623 100644 --- a/test/test.js +++ b/test/test.js @@ -124,6 +124,26 @@ ok(u instanceof URI, 'instanceof URI'); ok(u._parts.hostname !== undefined, 'host undefined'); }); + test('function URI(string) with invalid port "port" throws', function () { + raises(function () { + new URI('http://example.org:port'); + }, TypeError, "throws TypeError"); + }); + test('function URI(string) with invalid port "0" throws', function () { + raises(function () { + new URI('http://example.org:0'); + }, TypeError, "throws TypeError"); + }); + test('function URI(string) with invalid port "65536" throws', function () { + raises(function () { + new URI('http://example.org:65536'); + }, TypeError, "throws TypeError"); + }); + test('function URI(string) with protocol and without hostname should throw', function () { + raises(function () { + new URI('http://'); + }, TypeError, "throws TypeError"); + }); test('new URI(string, string)', function() { // see http://dvcs.w3.org/hg/url/raw-file/tip/Overview.html#constructor var u = new URI('../foobar.html', 'http://example.org/hello/world.html'); @@ -223,13 +243,16 @@ equal(u.hostname(), 'abc.foobar.lala', 'hostname changed'); equal(u+'', 'http://abc.foobar.lala/foo.html', 'hostname changed url'); - u.hostname(''); - equal(u.hostname(), '', 'hostname removed'); - equal(u+'', 'http:///foo.html', 'hostname removed url'); - raises(function() { u.hostname('foo\\bar.com'); }, TypeError, 'Failing backslash detection in hostname'); + + raises(function() { + u.hostname(''); + }, TypeError, "Trying to set an empty hostname with http(s) protocol throws a TypeError"); + raises(function() { + u.hostname(null); + }, TypeError, "Trying to set hostname to null with http(s) protocol throws a TypeError"); }); test('port', function() { var u = new URI('http://example.org/foo.html'); @@ -1338,11 +1361,6 @@ url: 'file:///C:/skyclan/snipkit', base: 'http://example.com/foo/bar', result: 'file:///C:/skyclan/snipkit' - }, { - name: 'absolute passthru - generic empty-hostname - urljoin (#328)', - url: 'http:///foo', - base: 'http://example.com/foo/bar', - result: 'http:///foo' }, { name: 'file paths - urljoin', url: 'anotherFile', From abe52cf5e76510ec54febaa990091985ec9deb36 Mon Sep 17 00:00:00 2001 From: Rodney Rehm Date: Tue, 8 Aug 2017 22:59:47 +0200 Subject: [PATCH 23/44] chore(build): bumping to version 1.18.11 --- CHANGELOG.md | 4 ++++ bower.json | 2 +- build.js | 2 +- package.json | 2 +- src/IPv6.js | 4 ++-- src/SecondLevelDomains.js | 2 +- src/URI.js | 4 ++-- src/URI.min.js | 4 ++-- src/URITemplate.js | 2 +- src/jquery.URI.js | 2 +- src/jquery.URI.min.js | 2 +- 11 files changed, 17 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d0b55ae..e05f5047 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ The release notes tracked in this document are also made available on the [releases page](https://github.com/medialize/URI.js/releases) +### 1.18.11 (August 8th 2017) ### + +* making [`URI.parse()`](http://medialize.github.io/URI.js/docs.html#static-parse) throw on invalid port and hostname - [Issue #344](https://github.com/medialize/URI.js/issues/344), [PR #345](https://github.com/medialize/URI.js/issues/345) + ### 1.18.10 (March 30th 2017) ### * adding support for [CentralNic](https://en.wikipedia.org/wiki/CentralNic#Second-level_domains) Second Level Domains - [Issue #333](https://github.com/medialize/URI.js/issues/333) diff --git a/bower.json b/bower.json index 7f5e5572..22779110 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "urijs", - "version": "1.18.10", + "version": "1.18.11", "main": "src/URI.js", "ignore": [ ".*", diff --git a/build.js b/build.js index 64c7c785..fdcd765e 100644 --- a/build.js +++ b/build.js @@ -29,7 +29,7 @@ function build(files) { output_format: "text", output_info: "compiled_code" }, function(data) { - var code = "/*! URI.js v1.18.10 http://medialize.github.io/URI.js/ */\n/* build contains: " + files.join(', ') + " */\n" + data; + var code = "/*! URI.js v1.18.11 http://medialize.github.io/URI.js/ */\n/* build contains: " + files.join(', ') + " */\n" + data; $progress.hide(); $out.val(code).parent().show(); $out.prev().find('a').remove(); diff --git a/package.json b/package.json index 5fccb719..dcf13258 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "urijs", - "version": "1.18.10", + "version": "1.18.11", "title": "URI.js - Mutating URLs", "author": { "name": "Rodney Rehm", diff --git a/src/IPv6.js b/src/IPv6.js index 3e98053c..6dc8d624 100644 --- a/src/IPv6.js +++ b/src/IPv6.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * IPv6 Support * - * Version: 1.18.10 + * Version: 1.18.11 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ @@ -174,7 +174,7 @@ if (root.IPv6 === this) { root.IPv6 = _IPv6; } - + return this; } diff --git a/src/SecondLevelDomains.js b/src/SecondLevelDomains.js index 3363d12e..154fb5d8 100644 --- a/src/SecondLevelDomains.js +++ b/src/SecondLevelDomains.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * Second Level Domain (SLD) Support * - * Version: 1.18.10 + * Version: 1.18.11 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/URI.js b/src/URI.js index f63ad6c6..03f2c6c1 100644 --- a/src/URI.js +++ b/src/URI.js @@ -1,7 +1,7 @@ /*! * URI.js - Mutating URLs * - * Version: 1.18.10 + * Version: 1.18.11 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ @@ -77,7 +77,7 @@ return this; } - URI.version = '1.18.10'; + URI.version = '1.18.11'; var p = URI.prototype; var hasOwn = Object.prototype.hasOwnProperty; diff --git a/src/URI.min.js b/src/URI.min.js index 9c66b0f9..c19eee40 100644 --- a/src/URI.min.js +++ b/src/URI.min.js @@ -1,4 +1,4 @@ -/*! URI.js v1.18.10 http://medialize.github.io/URI.js/ */ +/*! URI.js v1.18.11 http://medialize.github.io/URI.js/ */ /* build contains: IPv6.js, punycode.js, SecondLevelDomains.js, URI.js, URITemplate.js */ (function(g,k){"object"===typeof module&&module.exports?module.exports=k():"function"===typeof define&&define.amd?define(k):g.IPv6=k(g)})(this,function(g){var k=g&&g.IPv6;return{best:function(h){h=h.toLowerCase().split(":");var l=h.length,b=8;""===h[0]&&""===h[1]&&""===h[2]?(h.shift(),h.shift()):""===h[0]&&""===h[1]?h.shift():""===h[l-1]&&""===h[l-2]&&h.pop();l=h.length;-1!==h[l-1].indexOf(".")&&(b=7);var m;for(m=0;mg;g++)if("0"===l[0]&&1g&&(l=f,g=k)):"0"===h[m]&&(n=!0,f=m,k=1);k>g&&(l=f,g=k);1=l||l>=b-1)return null;var k=h.list[g.slice(b+1)];return!k||0>k.indexOf(" " (function(g,k){"object"===typeof module&&module.exports?module.exports=k(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"===typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],k):g.URI=k(g.punycode,g.IPv6,g.SecondLevelDomains,g)})(this,function(g,k,h,l){function b(a,c){var d=1<=arguments.length,p=2<=arguments.length;if(!(this instanceof b))return d?p?new b(a,c):new b(a):new b;if(void 0===a){if(d)throw new TypeError("undefined is not a valid argument for URI"); a="undefined"!==typeof location?location.href+"":""}if(null===a&&d)throw new TypeError("null is not a valid argument for URI");this.href(a);return void 0!==c?this.absoluteTo(c):this}function m(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function A(a){return void 0===a?"Undefined":String(Object.prototype.toString.call(a)).slice(8,-1)}function u(a){return"Array"===A(a)}function f(a,c){var d={},b,t;if("RegExp"===A(c))d=null;else if(u(c))for(b=0,t=c.length;b]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u2018\u2019]))/ig;b.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u201e\u2018\u2019]+$/,parens:/(\([^\)]*\)|\[[^\]]*\]|\{[^}]*\}|<[^>]*>)/g};b.defaultPorts={http:"80",https:"443",ftp:"21", gopher:"70",ws:"80",wss:"443"};b.invalid_hostname_characters=/[^a-zA-Z0-9\.-]/;b.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src",audio:"src",video:"src"};b.getDomAttribute=function(a){if(a&&a.nodeName){var c=a.nodeName.toLowerCase();if("input"!==c||"image"===a.type)return b.domAttributes[c]}};b.encode=y;b.decode=decodeURIComponent;b.iso8859=function(){b.encode=escape;b.decode= diff --git a/src/URITemplate.js b/src/URITemplate.js index eaeb8cc0..764c9482 100644 --- a/src/URITemplate.js +++ b/src/URITemplate.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * URI Template Support - http://tools.ietf.org/html/rfc6570 * - * Version: 1.18.10 + * Version: 1.18.11 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/jquery.URI.js b/src/jquery.URI.js index 307c4b4e..51be54ac 100644 --- a/src/jquery.URI.js +++ b/src/jquery.URI.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * jQuery Plugin * - * Version: 1.18.10 + * Version: 1.18.11 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/jquery-uri-plugin.html diff --git a/src/jquery.URI.min.js b/src/jquery.URI.min.js index f5d26910..c0cded56 100644 --- a/src/jquery.URI.min.js +++ b/src/jquery.URI.min.js @@ -1,4 +1,4 @@ -/*! URI.js v1.18.10 http://medialize.github.io/URI.js/ */ +/*! URI.js v1.18.11 http://medialize.github.io/URI.js/ */ /* build contains: jquery.URI.js */ (function(d,e){"object"===typeof module&&module.exports?module.exports=e(require("jquery"),require("./URI")):"function"===typeof define&&define.amd?define(["jquery","./URI"],e):e(d.jQuery,d.URI)})(this,function(d,e){function h(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function k(a){var b=a.nodeName.toLowerCase();if("input"!==b||"image"===a.type)return e.domAttributes[b]}function p(a){return{get:function(b){return d(b).uri()[a]()},set:function(b,c){d(b).uri()[a](c);return c}}}function l(a, b){var c,e,f;if(!k(a)||!b)return!1;c=b.match(q);if(!c||!c[5]&&":"!==c[2]&&!g[c[2]])return!1;f=d(a).uri();if(c[5])return f.is(c[5]);if(":"===c[2])return e=c[1].toLowerCase()+":",g[e]?g[e](f,c[4]):!1;e=c[1].toLowerCase();return m[e]?g[c[2]](f[e](),c[4],e):!1}var m={},g={"=":function(a,b){return a===b},"^=":function(a,b){return!!(a+"").match(new RegExp("^"+h(b),"i"))},"$=":function(a,b){return!!(a+"").match(new RegExp(h(b)+"$","i"))},"*=":function(a,b,c){"directory"===c&&(a+="/");return!!(a+"").match(new RegExp(h(b), From 8043e13921a836584e417820e9ab0fd8422cc721 Mon Sep 17 00:00:00 2001 From: Rodney Rehm Date: Tue, 8 Aug 2017 23:02:05 +0200 Subject: [PATCH 24/44] chore(dist): updating distributables to version 1.18.11 --- src/URI.min.js | 147 +++++++++++++++++++++--------------------- src/jquery.URI.min.js | 8 +-- 2 files changed, 78 insertions(+), 77 deletions(-) diff --git a/src/URI.min.js b/src/URI.min.js index c19eee40..d2de3c04 100644 --- a/src/URI.min.js +++ b/src/URI.min.js @@ -1,14 +1,14 @@ /*! URI.js v1.18.11 http://medialize.github.io/URI.js/ */ /* build contains: IPv6.js, punycode.js, SecondLevelDomains.js, URI.js, URITemplate.js */ -(function(g,k){"object"===typeof module&&module.exports?module.exports=k():"function"===typeof define&&define.amd?define(k):g.IPv6=k(g)})(this,function(g){var k=g&&g.IPv6;return{best:function(h){h=h.toLowerCase().split(":");var l=h.length,b=8;""===h[0]&&""===h[1]&&""===h[2]?(h.shift(),h.shift()):""===h[0]&&""===h[1]?h.shift():""===h[l-1]&&""===h[l-2]&&h.pop();l=h.length;-1!==h[l-1].indexOf(".")&&(b=7);var m;for(m=0;mg;g++)if("0"===l[0]&&1g&&(l=f,g=k)):"0"===h[m]&&(n=!0,f=m,k=1);k>g&&(l=f,g=k);1=g&&f>>10&1023|55296),b=56320|b&1023);return e+=r(b)}).join("")}function A(b,e){return b+22+75*(26>b)-((0!=e)<<5)}function u(b,e,f){var h=0;b=f?q(b/700):b>>1;for(b+=q(b/e);455d&&(d=0);for(p=0;p=f&&k("invalid-input");w=b.charCodeAt(d++); -w=10>w-48?w-22:26>w-65?w-65:26>w-97?w-97:36;(36<=w||w>q((2147483647-g)/h))&&k("overflow");g+=w*h;l=t<=c?1:t>=c+26?26:t-c;if(wq(2147483647/w)&&k("overflow");h*=w}h=e.length+1;c=u(g-p,h,0==p);q(g/h)>2147483647-a&&k("overflow");a+=q(g/h);g%=h;e.splice(g++,0,a)}return m(e)}function n(e){var f,h,g,l,a,c,d,p,t,w=[],n,m,z;e=b(e);n=e.length;f=128;h=0;a=72;for(c=0;ct&&w.push(r(t));for((g=l=w.length)&&w.push("-");g=f&&tq((2147483647-h)/m)&&k("overflow");h+=(d-f)*m;f=d;for(c=0;c=a+26?26:d-a;if(p= 0x80 (not a basic code point)","invalid-input":"Invalid input"},q=Math.floor,r=String.fromCharCode,C;y={version:"1.3.2",ucs2:{decode:b,encode:m},decode:f,encode:n,toASCII:function(b){return l(b,function(b){return x.test(b)?"xn--"+n(b):b})},toUnicode:function(b){return l(b,function(b){return E.test(b)?f(b.slice(4).toLowerCase()):b})}};if("function"== -typeof define&&"object"==typeof define.amd&&define.amd)define("punycode",function(){return y});else if(B&&z)if(module.exports==B)z.exports=y;else for(C in y)y.hasOwnProperty(C)&&(B[C]=y[C]);else g.punycode=y})(this); -(function(g,k){"object"===typeof module&&module.exports?module.exports=k():"function"===typeof define&&define.amd?define(k):g.SecondLevelDomains=k(g)})(this,function(g){var k=g&&g.SecondLevelDomains,h={list:{ac:" com gov mil net org ",ae:" ac co gov mil name net org pro sch ",af:" com edu gov net org ",al:" com edu gov mil net org ",ao:" co ed gv it og pb ",ar:" com edu gob gov int mil net org tur ",at:" ac co gv or ",au:" asn com csiro edu gov id net org ",ba:" co com edu gov mil net org rs unbi unmo unsa untz unze ", +(function(f,m){"object"===typeof module&&module.exports?module.exports=m():"function"===typeof define&&define.amd?define(m):f.IPv6=m(f)})(this,function(f){var m=f&&f.IPv6;return{best:function(h){h=h.toLowerCase().split(":");var k=h.length,b=8;""===h[0]&&""===h[1]&&""===h[2]?(h.shift(),h.shift()):""===h[0]&&""===h[1]?h.shift():""===h[k-1]&&""===h[k-2]&&h.pop();k=h.length;-1!==h[k-1].indexOf(".")&&(b=7);var q;for(q=0;qf;f++)if("0"===k[0]&&1f&&(k=g,f=m)):"0"===h[q]&&(p=!0,g=q,m=1);m>f&&(k=g,f=m);1=f&&g>>10&1023|55296),b=56320|b&1023);return e+=t(b)}).join("")}function z(b,e){return b+22+75*(26>b)-((0!=e)<<5)}function u(b,g,h){var f=0;b=h?e(b/700):b>>1;for(b+=e(b/g);455n&&(n=0);for(c=0;c=h&&m("invalid-input");var x=b.charCodeAt(n++); +x=10>x-48?x-22:26>x-65?x-65:26>x-97?x-97:36;(36<=x||x>e((2147483647-f)/l))&&m("overflow");f+=x*l;var p=d<=a?1:d>=a+26?26:d-a;if(xe(2147483647/x)&&m("overflow");l*=x}l=g.length+1;a=u(f-c,l,0==c);e(f/l)>2147483647-k&&m("overflow");k+=e(f/l);f%=l;g.splice(f++,0,k)}return q(g)}function p(g){var h,f,k,p=[];g=b(g);var a=g.length;var c=128;var d=0;var n=72;for(k=0;kl&&p.push(t(l))}for((h=f=p.length)&&p.push("-");h=c&& +le((2147483647-d)/q)&&m("overflow");d+=(x-c)*q;c=x;for(k=0;k=n+26?26:x-n;if(r= 0x80 (not a basic code point)","invalid-input":"Invalid input"},e=Math.floor,t=String.fromCharCode,y;var v={version:"1.3.2",ucs2:{decode:b,encode:q},decode:g,encode:p,toASCII:function(b){return k(b,function(b){return r.test(b)?"xn--"+p(b):b})},toUnicode:function(b){return k(b,function(b){return E.test(b)?g(b.slice(4).toLowerCase()): +b})}};if("function"==typeof define&&"object"==typeof define.amd&&define.amd)define("punycode",function(){return v});else if(D&&A)if(module.exports==D)A.exports=v;else for(y in v)v.hasOwnProperty(y)&&(D[y]=v[y]);else f.punycode=v})(this); +(function(f,m){"object"===typeof module&&module.exports?module.exports=m():"function"===typeof define&&define.amd?define(m):f.SecondLevelDomains=m(f)})(this,function(f){var m=f&&f.SecondLevelDomains,h={list:{ac:" com gov mil net org ",ae:" ac co gov mil name net org pro sch ",af:" com edu gov net org ",al:" com edu gov mil net org ",ao:" co ed gv it og pb ",ar:" com edu gob gov int mil net org tur ",at:" ac co gv or ",au:" asn com csiro edu gov id net org ",ba:" co com edu gov mil net org rs unbi unmo unsa untz unze ", bb:" biz co com edu gov info net org store tv ",bh:" biz cc com edu gov info net org ",bn:" com edu gov net org ",bo:" com edu gob gov int mil net org tv ",br:" adm adv agr am arq art ato b bio blog bmd cim cng cnt com coop ecn edu eng esp etc eti far flog fm fnd fot fst g12 ggf gov imb ind inf jor jus lel mat med mil mus net nom not ntr odo org ppg pro psc psi qsl rec slg srv tmp trd tur tv vet vlog wiki zlg ",bs:" com edu gov net org ",bz:" du et om ov rg ",ca:" ab bc mb nb nf nl ns nt nu on pe qc sk yk ", ck:" biz co edu gen gov info net org ",cn:" ac ah bj com cq edu fj gd gov gs gx gz ha hb he hi hl hn jl js jx ln mil net nm nx org qh sc sd sh sn sx tj tw xj xz yn zj ",co:" com edu gov mil net nom org ",cr:" ac c co ed fi go or sa ",cy:" ac biz com ekloges gov ltd name net org parliament press pro tm ","do":" art com edu gob gov mil net org sld web ",dz:" art asso com edu gov net org pol ",ec:" com edu fin gov info med mil net org pro ",eg:" com edu eun gov mil name net org sci ",er:" com edu gov ind mil net org rochest w ", es:" com edu gob nom org ",et:" biz com edu gov info name net org ",fj:" ac biz com info mil name net org pro ",fk:" ac co gov net nom org ",fr:" asso com f gouv nom prd presse tm ",gg:" co net org ",gh:" com edu gov mil org ",gn:" ac com gov net org ",gr:" com edu gov mil net org ",gt:" com edu gob ind mil net org ",gu:" com edu gov net org ",hk:" com edu gov idv net org ",hu:" 2000 agrar bolt casino city co erotica erotika film forum games hotel info ingatlan jogasz konyvelo lakas media news org priv reklam sex shop sport suli szex tm tozsde utazas video ", @@ -21,70 +21,71 @@ tw:" club com ebiz edu game gov idv mil net org ",mu:" ac co com gov net or org rw:" ac co com edu gouv gov int mil net ",sa:" com edu gov med net org pub sch ",sd:" com edu gov info med net org tv ",se:" a ac b bd c d e f g h i k l m n o org p parti pp press r s t tm u w x y z ",sg:" com edu gov idn net org per ",sn:" art com edu gouv org perso univ ",sy:" com edu gov mil net news org ",th:" ac co go in mi net or ",tj:" ac biz co com edu go gov info int mil name net nic org test web ",tn:" agrinet com defense edunet ens fin gov ind info intl mincom nat net org perso rnrt rns rnu tourism ", tz:" ac co go ne or ",ua:" biz cherkassy chernigov chernovtsy ck cn co com crimea cv dn dnepropetrovsk donetsk dp edu gov if in ivano-frankivsk kh kharkov kherson khmelnitskiy kiev kirovograd km kr ks kv lg lugansk lutsk lviv me mk net nikolaev od odessa org pl poltava pp rovno rv sebastopol sumy te ternopil uzhgorod vinnica vn zaporizhzhe zhitomir zp zt ",ug:" ac co go ne or org sc ",uk:" ac bl british-library co cym gov govt icnet jet lea ltd me mil mod national-library-scotland nel net nhs nic nls org orgn parliament plc police sch scot soc ", us:" dni fed isa kids nsn ",uy:" com edu gub mil net org ",ve:" co com edu gob info mil net org web ",vi:" co com k12 net org ",vn:" ac biz com edu gov health info int name net org pro ",ye:" co com gov ltd me net org plc ",yu:" ac co edu gov org ",za:" ac agric alt bourse city co cybernet db edu gov grondar iaccess imt inca landesign law mil net ngo nis nom olivetti org pix school tm web ",zm:" ac co com edu gov net org sch ",com:"ar br cn de eu gb gr hu jpn kr no qc ru sa se uk us uy za ",net:"gb jp se uk ", -org:"ae",de:"com "},has:function(g){var b=g.lastIndexOf(".");if(0>=b||b>=g.length-1)return!1;var l=g.lastIndexOf(".",b-1);if(0>=l||l>=b-1)return!1;var k=h.list[g.slice(b+1)];return k?0<=k.indexOf(" "+g.slice(l+1,b)+" "):!1},is:function(g){var b=g.lastIndexOf(".");if(0>=b||b>=g.length-1||0<=g.lastIndexOf(".",b-1))return!1;var l=h.list[g.slice(b+1)];return l?0<=l.indexOf(" "+g.slice(0,b)+" "):!1},get:function(g){var b=g.lastIndexOf(".");if(0>=b||b>=g.length-1)return null;var l=g.lastIndexOf(".",b-1); -if(0>=l||l>=b-1)return null;var k=h.list[g.slice(b+1)];return!k||0>k.indexOf(" "+g.slice(l+1,b)+" ")?null:g.slice(l+1)},noConflict:function(){g.SecondLevelDomains===this&&(g.SecondLevelDomains=k);return this}};return h}); -(function(g,k){"object"===typeof module&&module.exports?module.exports=k(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"===typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],k):g.URI=k(g.punycode,g.IPv6,g.SecondLevelDomains,g)})(this,function(g,k,h,l){function b(a,c){var d=1<=arguments.length,p=2<=arguments.length;if(!(this instanceof b))return d?p?new b(a,c):new b(a):new b;if(void 0===a){if(d)throw new TypeError("undefined is not a valid argument for URI"); -a="undefined"!==typeof location?location.href+"":""}if(null===a&&d)throw new TypeError("null is not a valid argument for URI");this.href(a);return void 0!==c?this.absoluteTo(c):this}function m(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function A(a){return void 0===a?"Undefined":String(Object.prototype.toString.call(a)).slice(8,-1)}function u(a){return"Array"===A(a)}function f(a,c){var d={},b,t;if("RegExp"===A(c))d=null;else if(u(c))for(b=0,t=c.length;b=b||b>=f.length-1)return!1;var k=f.lastIndexOf(".",b-1);if(0>=k||k>=b-1)return!1;var m=h.list[f.slice(b+1)];return m?0<=m.indexOf(" "+f.slice(k+1,b)+" "):!1},is:function(f){var b=f.lastIndexOf(".");if(0>=b||b>=f.length-1||0<=f.lastIndexOf(".",b-1))return!1;var k=h.list[f.slice(b+1)];return k?0<=k.indexOf(" "+f.slice(0,b)+" "):!1},get:function(f){var b=f.lastIndexOf(".");if(0>=b||b>=f.length-1)return null;var k=f.lastIndexOf(".",b-1); +if(0>=k||k>=b-1)return null;var m=h.list[f.slice(b+1)];return!m||0>m.indexOf(" "+f.slice(k+1,b)+" ")?null:f.slice(k+1)},noConflict:function(){f.SecondLevelDomains===this&&(f.SecondLevelDomains=m);return this}};return h}); +(function(f,m){"object"===typeof module&&module.exports?module.exports=m(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"===typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],m):f.URI=m(f.punycode,f.IPv6,f.SecondLevelDomains,f)})(this,function(f,m,h,k){function b(a,c){var d=1<=arguments.length,n=2<=arguments.length;if(!(this instanceof b))return d?n?new b(a,c):new b(a):new b;if(void 0===a){if(d)throw new TypeError("undefined is not a valid argument for URI"); +a="undefined"!==typeof location?location.href+"":""}if(null===a&&d)throw new TypeError("null is not a valid argument for URI");this.href(a);return void 0!==c?this.absoluteTo(c):this}function q(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function z(a){return void 0===a?"Undefined":String(Object.prototype.toString.call(a)).slice(8,-1)}function u(a){return"Array"===z(a)}function g(a,c){var d={},b;if("RegExp"===z(c))d=null;else if(u(c)){var l=0;for(b=c.length;l]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u2018\u2019]))/ig;b.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u201e\u2018\u2019]+$/,parens:/(\([^\)]*\)|\[[^\]]*\]|\{[^}]*\}|<[^>]*>)/g};b.defaultPorts={http:"80",https:"443",ftp:"21", -gopher:"70",ws:"80",wss:"443"};b.invalid_hostname_characters=/[^a-zA-Z0-9\.-]/;b.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src",audio:"src",video:"src"};b.getDomAttribute=function(a){if(a&&a.nodeName){var c=a.nodeName.toLowerCase();if("input"!==c||"image"===a.type)return b.domAttributes[c]}};b.encode=y;b.decode=decodeURIComponent;b.iso8859=function(){b.encode=escape;b.decode= -unescape};b.unicode=function(){b.encode=y;b.decode=decodeURIComponent};b.characters={pathname:{encode:{expression:/%(24|26|2B|2C|3B|3D|3A|40)/ig,map:{"%24":"$","%26":"&","%2B":"+","%2C":",","%3B":";","%3D":"=","%3A":":","%40":"@"}},decode:{expression:/[\/\?#]/g,map:{"/":"%2F","?":"%3F","#":"%23"}}},reserved:{encode:{expression:/%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/ig,map:{"%3A":":","%2F":"/","%3F":"?","%23":"#","%5B":"[","%5D":"]","%40":"@","%21":"!","%24":"$","%26":"&","%27":"'", -"%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"="}}},urnpath:{encode:{expression:/%(21|24|27|28|29|2A|2B|2C|3B|3D|40)/ig,map:{"%21":"!","%24":"$","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"=","%40":"@"}},decode:{expression:/[\/\?#:]/g,map:{"/":"%2F","?":"%3F","#":"%23",":":"%3A"}}}};b.encodeQuery=function(a,c){var d=b.encode(a+"");void 0===c&&(c=b.escapeQuerySpace);return c?d.replace(/%20/g,"+"):d};b.decodeQuery=function(a,c){a+="";void 0===c&& -(c=b.escapeQuerySpace);try{return b.decode(c?a.replace(/\+/g,"%20"):a)}catch(d){return a}};var r={encode:"encode",decode:"decode"},C,F=function(a,c){return function(d){try{return b[c](d+"").replace(b.characters[a][c].expression,function(d){return b.characters[a][c].map[d]})}catch(p){return d}}};for(C in r)b[C+"PathSegment"]=F("pathname",r[C]),b[C+"UrnPathSegment"]=F("urnpath",r[C]);r=function(a,c,d){return function(p){var t;t=d?function(a){return b[c](b[d](a))}:b[c];p=(p+"").split(a);for(var e=0, -f=p.length;eb)return a.charAt(0)===c.charAt(0)&&"/"===a.charAt(0)?"/":"";if("/"!==a.charAt(b)||"/"!==c.charAt(b))b=a.substring(0,b).lastIndexOf("/");return a.substring(0,b+1)};b.withinString=function(a,c,d){d||(d={}); -var e=d.start||b.findUri.start,f=d.end||b.findUri.end,g=d.trim||b.findUri.trim,h=d.parens||b.findUri.parens,l=/[a-z0-9-]=["']?$/i;for(e.lastIndex=0;;){var n=e.exec(a);if(!n)break;var k=n.index;if(d.ignoreHtml){var q=a.slice(Math.max(k-3,0),k);if(q&&l.test(q))continue}for(var m=k+a.slice(k).search(f),q=a.slice(k,m),m=-1;;){var z=h.exec(q);if(!z)break;m=Math.max(m,z.index+z[0].length)}q=-1d.length)return this._parts.hostname;d=this._parts.hostname.length-this.tld(c).length-1;d=this._parts.hostname.lastIndexOf(".",d-1)+1;return this._parts.hostname.substring(d)||""}if(!a)throw new TypeError("cannot set domain empty");b.ensureValidHostname(a); -!this._parts.hostname||this.is("IP")?this._parts.hostname=a:(d=new RegExp(m(this.domain())+"$"),this._parts.hostname=this._parts.hostname.replace(d,a));this.build(!c);return this};e.tld=function(a,c){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(c=a,a=void 0);if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var d=this._parts.hostname.lastIndexOf("."),d=this._parts.hostname.substring(d+1);return!0!==c&&h&&h.list[d.toLowerCase()]?h.get(this._parts.hostname)||d:d}if(a)if(a.match(/[^a-zA-Z0-9-]/))if(h&& -h.is(a))d=new RegExp(m(this.tld())+"$"),this._parts.hostname=this._parts.hostname.replace(d,a);else throw new TypeError('TLD "'+a+'" contains characters other than [A-Z0-9]');else{if(!this._parts.hostname||this.is("IP"))throw new ReferenceError("cannot set TLD on non-domain host");d=new RegExp(m(this.tld())+"$");this._parts.hostname=this._parts.hostname.replace(d,a)}else throw new TypeError("cannot set TLD empty");this.build(!c);return this};e.directory=function(a,c){if(this._parts.urn)return void 0=== -a?"":this;if(void 0===a||!0===a){if(!this._parts.path&&!this._parts.hostname)return"";if("/"===this._parts.path)return"/";var d=this._parts.path.length-this.filename().length-1,d=this._parts.path.substring(0,d)||(this._parts.hostname?"/":"");return a?b.decodePath(d):d}d=this._parts.path.length-this.filename().length;d=this._parts.path.substring(0,d);d=new RegExp("^"+m(d));this.is("relative")||(a||(a="/"),"/"!==a.charAt(0)&&(a="/"+a));a&&"/"!==a.charAt(a.length-1)&&(a+="/");a=b.recodePath(a);this._parts.path= -this._parts.path.replace(d,a);this.build(!c);return this};e.filename=function(a,c){if(this._parts.urn)return void 0===a?"":this;if("string"!==typeof a){if(!this._parts.path||"/"===this._parts.path)return"";var d=this._parts.path.lastIndexOf("/"),d=this._parts.path.substring(d+1);return a?b.decodePathSegment(d):d}d=!1;"/"===a.charAt(0)&&(a=a.substring(1));a.match(/\.?\//)&&(d=!0);var e=new RegExp(m(this.filename())+"$");a=b.recodePath(a);this._parts.path=this._parts.path.replace(e,a);d?this.normalizePath(c): -this.build(!c);return this};e.suffix=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path||"/"===this._parts.path)return"";var d=this.filename(),e=d.lastIndexOf(".");if(-1===e)return"";d=d.substring(e+1);d=/^[a-z0-9%]+$/i.test(d)?d:"";return a?b.decodePathSegment(d):d}"."===a.charAt(0)&&(a=a.substring(1));if(d=this.suffix())e=a?new RegExp(m(d)+"$"):new RegExp(m("."+d)+"$");else{if(!a)return this;this._parts.path+="."+b.recodePath(a)}e&&(a=b.recodePath(a), -this._parts.path=this._parts.path.replace(e,a));this.build(!c);return this};e.segment=function(a,c,d){var b=this._parts.urn?":":"/",e=this.path(),f="/"===e.substring(0,1),e=e.split(b);void 0!==a&&"number"!==typeof a&&(d=c,c=a,a=void 0);if(void 0!==a&&"number"!==typeof a)throw Error('Bad segment "'+a+'", must be 0-based integer');f&&e.shift();0>a&&(a=Math.max(e.length+a,0));if(void 0===c)return void 0===a?e:e[a];if(null===a||void 0===e[a])if(u(c)){e=[];a=0;for(var g=c.length;ab)return a.charAt(0)===c.charAt(0)&&"/"===a.charAt(0)?"/":"";if("/"!==a.charAt(b)||"/"!==c.charAt(b))b=a.substring(0, +b).lastIndexOf("/");return a.substring(0,b+1)};b.withinString=function(a,c,d){d||(d={});var n=d.start||b.findUri.start,l=d.end||b.findUri.end,e=d.trim||b.findUri.trim,g=d.parens||b.findUri.parens,f=/[a-z0-9-]=["']?$/i;for(n.lastIndex=0;;){var h=n.exec(a);if(!h)break;var k=h.index;if(d.ignoreHtml){var p=a.slice(Math.max(k-3,0),k);if(p&&f.test(p))continue}for(var m=k+a.slice(k).search(l),p=a.slice(k,m),m=-1;;){var r=g.exec(p);if(!r)break;m=Math.max(m,r.index+r[0].length)}p=-1c))throw new TypeError('Port "'+a+'" is not a valid port');}};b.noConflict=function(a){if(a)return a={URI:this.noConflict()},k.URITemplate&&"function"===typeof k.URITemplate.noConflict&&(a.URITemplate=k.URITemplate.noConflict()),k.IPv6&&"function"===typeof k.IPv6.noConflict&& +(a.IPv6=k.IPv6.noConflict()),k.SecondLevelDomains&&"function"===typeof k.SecondLevelDomains.noConflict&&(a.SecondLevelDomains=k.SecondLevelDomains.noConflict()),a;k.URI===this&&(k.URI=w);return this};e.build=function(a){if(!0===a)this._deferred_build=!0;else if(void 0===a||this._deferred_build)this._string=b.build(this._parts),this._deferred_build=!1;return this};e.clone=function(){return new b(this)};e.valueOf=e.toString=function(){return this.build(!1)._string};e.protocol=r("protocol");e.username= +r("username");e.password=r("password");e.hostname=r("hostname");e.port=r("port");e.query=C("query","?");e.fragment=C("fragment","#");e.search=function(a,c){var b=this.query(a,c);return"string"===typeof b&&b.length?"?"+b:b};e.hash=function(a,c){var b=this.fragment(a,c);return"string"===typeof b&&b.length?"#"+b:b};e.pathname=function(a,c){if(void 0===a||!0===a){var d=this._parts.path||(this._parts.hostname?"/":"");return a?(this._parts.urn?b.decodeUrnPath:b.decodePath)(d):d}this._parts.path=this._parts.urn? +a?b.recodeUrnPath(a):"":a?b.recodePath(a):"/";this.build(!c);return this};e.path=e.pathname;e.href=function(a,c){var d;if(void 0===a)return this.toString();this._string="";this._parts=b._parts();var e=a instanceof b,l="object"===typeof a&&(a.hostname||a.path||a.pathname);a.nodeName&&(l=b.getDomAttribute(a),a=a[l]||"",l=!1);!e&&l&&void 0!==a.pathname&&(a=a.toString());if("string"===typeof a||a instanceof String)this._parts=b.parse(String(a),this._parts);else if(e||l)for(d in e=e?a._parts:a,e)t.call(this._parts, +d)&&(this._parts[d]=e[d]);else throw new TypeError("invalid input");this.build(!c);return this};e.is=function(a){var c=!1,d=!1,e=!1,l=!1,g=!1,f=!1,k=!1,p=!this._parts.urn;this._parts.hostname&&(p=!1,d=b.ip4_expression.test(this._parts.hostname),e=b.ip6_expression.test(this._parts.hostname),c=d||e,g=(l=!c)&&h&&h.has(this._parts.hostname),f=l&&b.idn_expression.test(this._parts.hostname),k=l&&b.punycode_expression.test(this._parts.hostname));switch(a.toLowerCase()){case "relative":return p;case "absolute":return!p; +case "domain":case "name":return l;case "sld":return g;case "ip":return c;case "ip4":case "ipv4":case "inet4":return d;case "ip6":case "ipv6":case "inet6":return e;case "idn":return f;case "url":return!this._parts.urn;case "urn":return!!this._parts.urn;case "punycode":return k}return null};var G=e.protocol,H=e.port,I=e.hostname;e.protocol=function(a,c){if(void 0!==a&&a&&(a=a.replace(/:(\/\/)?$/,""),!a.match(b.protocol_expression)))throw new TypeError('Protocol "'+a+"\" contains characters other than [A-Z0-9.+-] or doesn't start with [A-Z]"); +return G.call(this,a,c)};e.scheme=e.protocol;e.port=function(a,c){if(this._parts.urn)return void 0===a?"":this;void 0!==a&&(0===a&&(a=null),a&&(a+="",":"===a.charAt(0)&&(a=a.substring(1)),b.ensureValidPort(a)));return H.call(this,a,c)};e.hostname=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0!==a){var d={};if("/"!==b.parseHost(a,d))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]');a=d.hostname;b.ensureValidHostname(a,this._parts.protocol)}return I.call(this, +a,c)};e.origin=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){var d=this.protocol();return this.authority()?(d?d+"://":"")+this.authority():""}d=b(a);this.protocol(d.protocol()).authority(d.authority()).build(!c);return this};e.host=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a)return this._parts.hostname?b.buildHost(this._parts):"";if("/"!==b.parseHost(a,this._parts))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]'); +this.build(!c);return this};e.authority=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a)return this._parts.hostname?b.buildAuthority(this._parts):"";if("/"!==b.parseAuthority(a,this._parts))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]');this.build(!c);return this};e.userinfo=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){var d=b.buildUserinfo(this._parts);return d?d.substring(0,d.length-1):d}"@"!==a[a.length-1]&& +(a+="@");b.parseUserinfo(a,this._parts);this.build(!c);return this};e.resource=function(a,c){if(void 0===a)return this.path()+this.search()+this.hash();var d=b.parse(a);this._parts.path=d.path;this._parts.query=d.query;this._parts.fragment=d.fragment;this.build(!c);return this};e.subdomain=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var d=this._parts.hostname.length-this.domain().length-1;return this._parts.hostname.substring(0, +d)||""}d=this._parts.hostname.length-this.domain().length;d=this._parts.hostname.substring(0,d);d=new RegExp("^"+q(d));a&&"."!==a.charAt(a.length-1)&&(a+=".");if(-1!==a.indexOf(":"))throw new TypeError("Domains cannot contain colons");a&&b.ensureValidHostname(a,this._parts.protocol);this._parts.hostname=this._parts.hostname.replace(d,a);this.build(!c);return this};e.domain=function(a,c){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(c=a,a=void 0);if(void 0===a){if(!this._parts.hostname|| +this.is("IP"))return"";var d=this._parts.hostname.match(/\./g);if(d&&2>d.length)return this._parts.hostname;d=this._parts.hostname.length-this.tld(c).length-1;d=this._parts.hostname.lastIndexOf(".",d-1)+1;return this._parts.hostname.substring(d)||""}if(!a)throw new TypeError("cannot set domain empty");if(-1!==a.indexOf(":"))throw new TypeError("Domains cannot contain colons");b.ensureValidHostname(a,this._parts.protocol);!this._parts.hostname||this.is("IP")?this._parts.hostname=a:(d=new RegExp(q(this.domain())+ +"$"),this._parts.hostname=this._parts.hostname.replace(d,a));this.build(!c);return this};e.tld=function(a,c){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(c=a,a=void 0);if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var b=this._parts.hostname.lastIndexOf("."),b=this._parts.hostname.substring(b+1);return!0!==c&&h&&h.list[b.toLowerCase()]?h.get(this._parts.hostname)||b:b}if(a)if(a.match(/[^a-zA-Z0-9-]/))if(h&&h.is(a))b=new RegExp(q(this.tld())+"$"),this._parts.hostname= +this._parts.hostname.replace(b,a);else throw new TypeError('TLD "'+a+'" contains characters other than [A-Z0-9]');else{if(!this._parts.hostname||this.is("IP"))throw new ReferenceError("cannot set TLD on non-domain host");b=new RegExp(q(this.tld())+"$");this._parts.hostname=this._parts.hostname.replace(b,a)}else throw new TypeError("cannot set TLD empty");this.build(!c);return this};e.directory=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path&& +!this._parts.hostname)return"";if("/"===this._parts.path)return"/";var d=this._parts.path.length-this.filename().length-1,d=this._parts.path.substring(0,d)||(this._parts.hostname?"/":"");return a?b.decodePath(d):d}d=this._parts.path.length-this.filename().length;d=this._parts.path.substring(0,d);d=new RegExp("^"+q(d));this.is("relative")||(a||(a="/"),"/"!==a.charAt(0)&&(a="/"+a));a&&"/"!==a.charAt(a.length-1)&&(a+="/");a=b.recodePath(a);this._parts.path=this._parts.path.replace(d,a);this.build(!c); +return this};e.filename=function(a,c){if(this._parts.urn)return void 0===a?"":this;if("string"!==typeof a){if(!this._parts.path||"/"===this._parts.path)return"";var d=this._parts.path.lastIndexOf("/"),d=this._parts.path.substring(d+1);return a?b.decodePathSegment(d):d}d=!1;"/"===a.charAt(0)&&(a=a.substring(1));a.match(/\.?\//)&&(d=!0);var e=new RegExp(q(this.filename())+"$");a=b.recodePath(a);this._parts.path=this._parts.path.replace(e,a);d?this.normalizePath(c):this.build(!c);return this};e.suffix= +function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path||"/"===this._parts.path)return"";var d=this.filename(),e=d.lastIndexOf(".");if(-1===e)return"";d=d.substring(e+1);d=/^[a-z0-9%]+$/i.test(d)?d:"";return a?b.decodePathSegment(d):d}"."===a.charAt(0)&&(a=a.substring(1));if(d=this.suffix())e=a?new RegExp(q(d)+"$"):new RegExp(q("."+d)+"$");else{if(!a)return this;this._parts.path+="."+b.recodePath(a)}e&&(a=b.recodePath(a),this._parts.path=this._parts.path.replace(e, +a));this.build(!c);return this};e.segment=function(a,c,b){var d=this._parts.urn?":":"/",e=this.path(),g="/"===e.substring(0,1),e=e.split(d);void 0!==a&&"number"!==typeof a&&(b=c,c=a,a=void 0);if(void 0!==a&&"number"!==typeof a)throw Error('Bad segment "'+a+'", must be 0-based integer');g&&e.shift();0>a&&(a=Math.max(e.length+a,0));if(void 0===c)return void 0===a?e:e[a];if(null===a||void 0===e[a])if(u(c)){e=[];a=0;for(var f=c.length;a{}"`^| \\]/;h.expand=function(b,g,l){var f=u[b.operator],n=f.named?"Named":"Unnamed";b=b.variables;var k=[],m,x,v;for(v=0;x=b[v];v++){m=g.get(x.name);if(0===m.type&&l&&l.strict)throw Error('Missing expansion value for variable "'+ -x.name+'"');if(m.val.length){if(1{}"`^| \\]/;h.expand=function(b,f,k){var g=u[b.operator],p=g.named?"Named":"Unnamed";b=b.variables;var m=[],r,q;for(q=0;r=b[q];q++){var w=f.get(r.name);if(0===w.type&&k&&k.strict)throw Error('Missing expansion value for variable "'+ +r.name+'"');if(w.val.length){if(1 Date: Wed, 9 Aug 2017 20:56:44 +0300 Subject: [PATCH 25/44] fix(parse): allow _ in hostnames (#347 #348) --- src/URI.js | 10 +++++----- test/test.js | 19 +++++++++++++++++++ test/urls.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 5 deletions(-) diff --git a/src/URI.js b/src/URI.js index 03f2c6c1..15936505 100644 --- a/src/URI.js +++ b/src/URI.js @@ -207,7 +207,7 @@ URI.escapeQuerySpace = true; // static properties URI.protocol_expression = /^[a-z][a-z0-9.+-]*$/i; - URI.idn_expression = /[^a-z0-9\.-]/i; + URI.idn_expression = /[^a-z0-9\._-]/i; URI.punycode_expression = /(xn--)/i; // well, 333.444.555.666 matches, but it sure ain't no IPv4 - do we care? URI.ip4_expression = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/; @@ -248,8 +248,8 @@ // allowed hostname characters according to RFC 3986 // ALPHA DIGIT "-" "." "_" "~" "!" "$" "&" "'" "(" ")" "*" "+" "," ";" "=" %encoded - // I've never seen a (non-IDN) hostname other than: ALPHA DIGIT . - - URI.invalid_hostname_characters = /[^a-zA-Z0-9\.\-:]/; + // I've never seen a (non-IDN) hostname other than: ALPHA DIGIT . - _ + URI.invalid_hostname_characters = /[^a-zA-Z0-9\.\-:_]/; // map DOM Elements to their URI attribute URI.domAttributes = { 'a': 'href', @@ -1044,10 +1044,10 @@ } else if (v && v.match(URI.invalid_hostname_characters)) { // test punycode if (!punycode) { - throw new TypeError('Hostname "' + v + '" contains characters other than [A-Z0-9.-] and Punycode.js is not available'); + throw new TypeError('Hostname "' + v + '" contains characters other than [A-Z0-9.-:_] and Punycode.js is not available'); } if (punycode.toASCII(v).match(URI.invalid_hostname_characters)) { - throw new TypeError('Hostname "' + v + '" contains characters other than [A-Z0-9.:-]'); + throw new TypeError('Hostname "' + v + '" contains characters other than [A-Z0-9.-:_]'); } } }; diff --git a/test/test.js b/test/test.js index 8ebf8623..77bee55f 100644 --- a/test/test.js +++ b/test/test.js @@ -243,6 +243,10 @@ equal(u.hostname(), 'abc.foobar.lala', 'hostname changed'); equal(u+'', 'http://abc.foobar.lala/foo.html', 'hostname changed url'); + u.hostname('some_where.exa_mple.org'); + equal(u.hostname(), 'some_where.exa_mple.org', 'hostname changed'); + equal(u+'', 'http://some_where.exa_mple.org/foo.html', 'hostname changed url'); + raises(function() { u.hostname('foo\\bar.com'); }, TypeError, 'Failing backslash detection in hostname'); @@ -395,6 +399,11 @@ equal(u.port(), '', 'host removed port'); equal(u+'', 'http://some-domain.com/foo.html', 'host modified url'); + u.host('some_where.exa_mple.org:44'); + equal(u.hostname(), 'some_where.exa_mple.org', 'host modified hostname #2'); + equal(u.port(), '44', 'port restored'); + equal(u+'', 'http://some_where.exa_mple.org:44/foo.html', 'host modified url #2'); + raises(function() { u.host('foo\\bar.com'); }, TypeError, 'Failing backslash detection in host'); @@ -524,6 +533,9 @@ equal(u.hostname(), 'foo.example.org', 'changed subdomain foo.'); equal(u+'', 'http://foo.example.org/foo.html', 'changed url foo.'); + u.subdomain('foo_bar'); + equal(u.hostname(), 'foo_bar.example.org', 'changed subdomain foo_bar'); + equal(u+'', 'http://foo_bar.example.org/foo.html', 'changed url foo_bar'); }); test('domain', function() { var u = new URI('http://www.example.org/foo.html'); @@ -554,6 +566,13 @@ u.subdomain('foo'); equal(u.href(), 'http://foo.test/', 'subdomain set on (dot-less)'); + + u.subdomain('bar'); + equal(u.href(), 'http://bar.foo.test/', 'subdomain set on foo.test'); + + u.domain('exam_ple.org'); + equal(u.domain(), 'exam_ple.org', 'domain after changed domain exam_ple.org'); + equal(u+'', 'http://bar.exam_ple.org/', 'url after changed domain exam_ple.org'); }); test('tld', function() { var u = new URI('http://www.example.org/foo.html'); diff --git a/test/urls.js b/test/urls.js index b38337ec..06e4ae54 100644 --- a/test/urls.js +++ b/test/urls.js @@ -1112,6 +1112,55 @@ var urls = [{ idn: false, punycode: false } + }, { + // https://github.com/medialize/URI.js/issues/347 + name: 'Underscore in domain', + url: 'http://user:pass@some_where.exa_mple.org:123/some/directory/file.html?query=string#fragment', + parts: { + protocol: 'http', + username: 'user', + password: 'pass', + hostname: 'some_where.exa_mple.org', + port: '123', + path: '/some/directory/file.html', + query: 'query=string', + fragment: 'fragment' + }, + accessors: { + protocol: 'http', + username: 'user', + password: 'pass', + port: '123', + path: '/some/directory/file.html', + query: 'query=string', + fragment: 'fragment', + resource: '/some/directory/file.html?query=string#fragment', + authority: 'user:pass@some_where.exa_mple.org:123', + origin: 'http://user:pass@some_where.exa_mple.org:123', + userinfo: 'user:pass', + subdomain: 'some_where', + domain: 'exa_mple.org', + tld: 'org', + directory: '/some/directory', + filename: 'file.html', + suffix: 'html', + hash: '#fragment', + search: '?query=string', + host: 'some_where.exa_mple.org:123', + hostname: 'some_where.exa_mple.org' + }, + is: { + urn: false, + url: true, + relative: false, + name: true, + sld: false, + ip: false, + ip4: false, + ip6: false, + idn: false, + punycode: false + } }, { name: 'IDN (punycode)', url: 'http://user:pass@xn--exmple-cua.org:123/some/directory/file.html?query=string#fragment', From 0d20f985b1a2e93679d5f5cb6ee992e8889a236a Mon Sep 17 00:00:00 2001 From: Jeffrey Phillips Date: Thu, 10 Aug 2017 14:30:39 -0400 Subject: [PATCH 26/44] fix(ensureValidPort): replace Number.isInteger() with local util (#350, #351) --- src/URI.js | 6 +++++- test/test.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/URI.js b/src/URI.js index 15936505..1e25535e 100644 --- a/src/URI.js +++ b/src/URI.js @@ -77,6 +77,10 @@ return this; } + function isInteger(value) { + return /^[0-9]+$/.test(value); + } + URI.version = '1.18.11'; var p = URI.prototype; @@ -1058,7 +1062,7 @@ } var port = Number(v); - if (Number.isInteger(port) && (port > 0) && (port < 65536)) { + if (isInteger(port) && (port > 0) && (port < 65536)) { return; } diff --git a/test/test.js b/test/test.js index 77bee55f..d6efe220 100644 --- a/test/test.js +++ b/test/test.js @@ -1700,6 +1700,36 @@ deepEqual(links, expected, 'urls extracted'); equal(result, source, 'source not modified'); }); + test('ensureValidPort', function() { + + function testPort(value) { + var result = true; + try { + URI.ensureValidPort(value); + } catch(e) { + result = false; + } + + return result; + } + + equal(testPort(8000), true); + equal(testPort('8080'), true); + + equal(testPort(0), true); + equal(testPort(1), true); + + equal(testPort(65535), true); + equal(testPort(65536), false); + + equal(testPort(-8080), false); + equal(testPort('-8080'), false); + + equal(testPort('aaa8080'), false); + equal(testPort('8080a'), false); + + equal(testPort(8080.2), false); + }); test('noConflict', function() { var actual_lib = URI; // actual library; after loading, before noConflict() var unconflicted = URI.noConflict(); From 7074a5bcdee2b2ac4d48370fe7e04a488a18db0f Mon Sep 17 00:00:00 2001 From: Rodney Rehm Date: Thu, 10 Aug 2017 20:35:14 +0200 Subject: [PATCH 27/44] chore(build): bumping to version 1.18.12 --- CHANGELOG.md | 5 +++++ bower.json | 2 +- build.js | 2 +- package.json | 2 +- src/IPv6.js | 2 +- src/SecondLevelDomains.js | 2 +- src/URI.js | 4 ++-- src/URI.min.js | 4 ++-- src/URITemplate.js | 2 +- src/jquery.URI.js | 2 +- src/jquery.URI.min.js | 2 +- 11 files changed, 17 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e05f5047..caf7b0f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ The release notes tracked in this document are also made available on the [releases page](https://github.com/medialize/URI.js/releases) +### 1.18.12 (August 9th 2017) ### + +* making [`URI.parse()`](http://medialize.github.io/URI.js/docs.html#static-parse) allow `_` in hostname - [Issue #347](https://github.com/medialize/URI.js/issues/347), [PR #348](https://github.com/medialize/URI.js/issues/348) +* fixing [`URI.parse()`](http://medialize.github.io/URI.js/docs.html#static-parse) to not use `Number.isNumber()` for IE compatibility - [Issue #350](https://github.com/medialize/URI.js/issues/350), [PR #351](https://github.com/medialize/URI.js/issues/351) + ### 1.18.11 (August 8th 2017) ### * making [`URI.parse()`](http://medialize.github.io/URI.js/docs.html#static-parse) throw on invalid port and hostname - [Issue #344](https://github.com/medialize/URI.js/issues/344), [PR #345](https://github.com/medialize/URI.js/issues/345) diff --git a/bower.json b/bower.json index 22779110..c282151f 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "urijs", - "version": "1.18.11", + "version": "1.18.12", "main": "src/URI.js", "ignore": [ ".*", diff --git a/build.js b/build.js index fdcd765e..9b8ca747 100644 --- a/build.js +++ b/build.js @@ -29,7 +29,7 @@ function build(files) { output_format: "text", output_info: "compiled_code" }, function(data) { - var code = "/*! URI.js v1.18.11 http://medialize.github.io/URI.js/ */\n/* build contains: " + files.join(', ') + " */\n" + data; + var code = "/*! URI.js v1.18.12 http://medialize.github.io/URI.js/ */\n/* build contains: " + files.join(', ') + " */\n" + data; $progress.hide(); $out.val(code).parent().show(); $out.prev().find('a').remove(); diff --git a/package.json b/package.json index dcf13258..67b1e2fc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "urijs", - "version": "1.18.11", + "version": "1.18.12", "title": "URI.js - Mutating URLs", "author": { "name": "Rodney Rehm", diff --git a/src/IPv6.js b/src/IPv6.js index 6dc8d624..5fbf3a18 100644 --- a/src/IPv6.js +++ b/src/IPv6.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * IPv6 Support * - * Version: 1.18.11 + * Version: 1.18.12 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/SecondLevelDomains.js b/src/SecondLevelDomains.js index 154fb5d8..da6d1a31 100644 --- a/src/SecondLevelDomains.js +++ b/src/SecondLevelDomains.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * Second Level Domain (SLD) Support * - * Version: 1.18.11 + * Version: 1.18.12 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/URI.js b/src/URI.js index 1e25535e..47e6d9a7 100644 --- a/src/URI.js +++ b/src/URI.js @@ -1,7 +1,7 @@ /*! * URI.js - Mutating URLs * - * Version: 1.18.11 + * Version: 1.18.12 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ @@ -81,7 +81,7 @@ return /^[0-9]+$/.test(value); } - URI.version = '1.18.11'; + URI.version = '1.18.12'; var p = URI.prototype; var hasOwn = Object.prototype.hasOwnProperty; diff --git a/src/URI.min.js b/src/URI.min.js index d2de3c04..6d60b72f 100644 --- a/src/URI.min.js +++ b/src/URI.min.js @@ -1,4 +1,4 @@ -/*! URI.js v1.18.11 http://medialize.github.io/URI.js/ */ +/*! URI.js v1.18.12 http://medialize.github.io/URI.js/ */ /* build contains: IPv6.js, punycode.js, SecondLevelDomains.js, URI.js, URITemplate.js */ (function(f,m){"object"===typeof module&&module.exports?module.exports=m():"function"===typeof define&&define.amd?define(m):f.IPv6=m(f)})(this,function(f){var m=f&&f.IPv6;return{best:function(h){h=h.toLowerCase().split(":");var k=h.length,b=8;""===h[0]&&""===h[1]&&""===h[2]?(h.shift(),h.shift()):""===h[0]&&""===h[1]?h.shift():""===h[k-1]&&""===h[k-2]&&h.pop();k=h.length;-1!==h[k-1].indexOf(".")&&(b=7);var q;for(q=0;qf;f++)if("0"===k[0]&&1f&&(k=g,f=m)):"0"===h[q]&&(p=!0,g=q,m=1);m>f&&(k=g,f=m);1=k||k>=b-1)return null;var m=h.list[f.slice(b+1)];return!m||0>m.indexOf(" " (function(f,m){"object"===typeof module&&module.exports?module.exports=m(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"===typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],m):f.URI=m(f.punycode,f.IPv6,f.SecondLevelDomains,f)})(this,function(f,m,h,k){function b(a,c){var d=1<=arguments.length,n=2<=arguments.length;if(!(this instanceof b))return d?n?new b(a,c):new b(a):new b;if(void 0===a){if(d)throw new TypeError("undefined is not a valid argument for URI"); a="undefined"!==typeof location?location.href+"":""}if(null===a&&d)throw new TypeError("null is not a valid argument for URI");this.href(a);return void 0!==c?this.absoluteTo(c):this}function q(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function z(a){return void 0===a?"Undefined":String(Object.prototype.toString.call(a)).slice(8,-1)}function u(a){return"Array"===z(a)}function g(a,c){var d={},b;if("RegExp"===z(c))d=null;else if(u(c)){var l=0;for(b=c.length;l]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u2018\u2019]))/ig;b.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u201e\u2018\u2019]+$/,parens:/(\([^\)]*\)|\[[^\]]*\]|\{[^}]*\}|<[^>]*>)/g};b.defaultPorts={http:"80",https:"443",ftp:"21", gopher:"70",ws:"80",wss:"443"};b.hostProtocols=["http","https"];b.invalid_hostname_characters=/[^a-zA-Z0-9\.\-:]/;b.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src",audio:"src",video:"src"};b.getDomAttribute=function(a){if(a&&a.nodeName){var c=a.nodeName.toLowerCase();if("input"!==c||"image"===a.type)return b.domAttributes[c]}};b.encode=E;b.decode=decodeURIComponent;b.iso8859= diff --git a/src/URITemplate.js b/src/URITemplate.js index 764c9482..b59f1481 100644 --- a/src/URITemplate.js +++ b/src/URITemplate.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * URI Template Support - http://tools.ietf.org/html/rfc6570 * - * Version: 1.18.11 + * Version: 1.18.12 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/jquery.URI.js b/src/jquery.URI.js index 51be54ac..e56465ce 100644 --- a/src/jquery.URI.js +++ b/src/jquery.URI.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * jQuery Plugin * - * Version: 1.18.11 + * Version: 1.18.12 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/jquery-uri-plugin.html diff --git a/src/jquery.URI.min.js b/src/jquery.URI.min.js index faa7f1a2..40c5eabd 100644 --- a/src/jquery.URI.min.js +++ b/src/jquery.URI.min.js @@ -1,4 +1,4 @@ -/*! URI.js v1.18.11 http://medialize.github.io/URI.js/ */ +/*! URI.js v1.18.12 http://medialize.github.io/URI.js/ */ /* build contains: jquery.URI.js */ (function(d,e){"object"===typeof module&&module.exports?module.exports=e(require("jquery"),require("./URI")):"function"===typeof define&&define.amd?define(["jquery","./URI"],e):e(d.jQuery,d.URI)})(this,function(d,e){function h(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function k(a){var b=a.nodeName.toLowerCase();if("input"!==b||"image"===a.type)return e.domAttributes[b]}function n(a){return{get:function(b){return d(b).uri()[a]()},set:function(b,c){d(b).uri()[a](c);return c}}}function l(a, b){if(!k(a)||!b)return!1;var c=b.match(p);if(!c||!c[5]&&":"!==c[2]&&!g[c[2]])return!1;var e=d(a).uri();if(c[5])return e.is(c[5]);if(":"===c[2]){var f=c[1].toLowerCase()+":";return g[f]?g[f](e,c[4]):!1}f=c[1].toLowerCase();return m[f]?g[c[2]](e[f](),c[4],f):!1}var m={},g={"=":function(a,b){return a===b},"^=":function(a,b){return!!(a+"").match(new RegExp("^"+h(b),"i"))},"$=":function(a,b){return!!(a+"").match(new RegExp(h(b)+"$","i"))},"*=":function(a,b,c){"directory"===c&&(a+="/");return!!(a+"").match(new RegExp(h(b), From 61cd727e65b8103110c6e207188e2250f5677213 Mon Sep 17 00:00:00 2001 From: Rodney Rehm Date: Thu, 10 Aug 2017 20:37:24 +0200 Subject: [PATCH 28/44] chore(dist): updating distributables to version 1.18.12 --- src/URI.min.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/URI.min.js b/src/URI.min.js index 6d60b72f..91755685 100644 --- a/src/URI.min.js +++ b/src/URI.min.js @@ -27,9 +27,9 @@ if(0>=k||k>=b-1)return null;var m=h.list[f.slice(b+1)];return!m||0>m.indexOf(" " a="undefined"!==typeof location?location.href+"":""}if(null===a&&d)throw new TypeError("null is not a valid argument for URI");this.href(a);return void 0!==c?this.absoluteTo(c):this}function q(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function z(a){return void 0===a?"Undefined":String(Object.prototype.toString.call(a)).slice(8,-1)}function u(a){return"Array"===z(a)}function g(a,c){var d={},b;if("RegExp"===z(c))d=null;else if(u(c)){var l=0;for(b=c.length;l]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u2018\u2019]))/ig;b.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u201e\u2018\u2019]+$/,parens:/(\([^\)]*\)|\[[^\]]*\]|\{[^}]*\}|<[^>]*>)/g};b.defaultPorts={http:"80",https:"443",ftp:"21", -gopher:"70",ws:"80",wss:"443"};b.hostProtocols=["http","https"];b.invalid_hostname_characters=/[^a-zA-Z0-9\.\-:]/;b.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src",audio:"src",video:"src"};b.getDomAttribute=function(a){if(a&&a.nodeName){var c=a.nodeName.toLowerCase();if("input"!==c||"image"===a.type)return b.domAttributes[c]}};b.encode=E;b.decode=decodeURIComponent;b.iso8859= +gopher:"70",ws:"80",wss:"443"};b.hostProtocols=["http","https"];b.invalid_hostname_characters=/[^a-zA-Z0-9\.\-:_]/;b.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src",audio:"src",video:"src"};b.getDomAttribute=function(a){if(a&&a.nodeName){var c=a.nodeName.toLowerCase();if("input"!==c||"image"===a.type)return b.domAttributes[c]}};b.encode=E;b.decode=decodeURIComponent;b.iso8859= function(){b.encode=escape;b.decode=unescape};b.unicode=function(){b.encode=E;b.decode=decodeURIComponent};b.characters={pathname:{encode:{expression:/%(24|26|2B|2C|3B|3D|3A|40)/ig,map:{"%24":"$","%26":"&","%2B":"+","%2C":",","%3B":";","%3D":"=","%3A":":","%40":"@"}},decode:{expression:/[\/\?#]/g,map:{"/":"%2F","?":"%3F","#":"%23"}}},reserved:{encode:{expression:/%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/ig,map:{"%3A":":","%2F":"/","%3F":"?","%23":"#","%5B":"[","%5D":"]","%40":"@", "%21":"!","%24":"$","%26":"&","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"="}}},urnpath:{encode:{expression:/%(21|24|27|28|29|2A|2B|2C|3B|3D|40)/ig,map:{"%21":"!","%24":"$","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"=","%40":"@"}},decode:{expression:/[\/\?#:]/g,map:{"/":"%2F","?":"%3F","#":"%23",":":"%3A"}}}};b.encodeQuery=function(a,c){var d=b.encode(a+"");void 0===c&&(c=b.escapeQuerySpace);return c?d.replace(/%20/g,"+"):d};b.decodeQuery= function(a,c){a+="";void 0===c&&(c=b.escapeQuerySpace);try{return b.decode(c?a.replace(/\+/g,"%20"):a)}catch(d){return a}};var y={encode:"encode",decode:"decode"},v,F=function(a,c){return function(d){try{return b[c](d+"").replace(b.characters[a][c].expression,function(d){return b.characters[a][c].map[d]})}catch(n){return d}}};for(v in y)b[v+"PathSegment"]=F("pathname",y[v]),b[v+"UrnPathSegment"]=F("urnpath",y[v]);y=function(a,c,d){return function(n){var l=d?function(a){return b[c](b[d](a))}:b[c]; @@ -45,8 +45,8 @@ else throw new TypeError("URI.removeQuery() accepts an object, string, RegExp as a;case "Boolean":return a=!(u(a[c])?!a[c].length:!a[c]),d===a;case "Function":return!!d(a[c],c,a);case "Array":return u(a[c])?(n?p:D)(a[c],d):!1;case "RegExp":return u(a[c])?n?p(a[c],d):!1:!(!a[c]||!a[c].match(d));case "Number":d=String(d);case "String":return u(a[c])?n?p(a[c],d):!1:a[c]===d;default:throw new TypeError("URI.hasQuery() accepts undefined, boolean, string, number, RegExp, Function as the value parameter");}};b.joinPaths=function(){for(var a=[],c=[],d=0,n=0;nb)return a.charAt(0)===c.charAt(0)&&"/"===a.charAt(0)?"/":"";if("/"!==a.charAt(b)||"/"!==c.charAt(b))b=a.substring(0, b).lastIndexOf("/");return a.substring(0,b+1)};b.withinString=function(a,c,d){d||(d={});var n=d.start||b.findUri.start,l=d.end||b.findUri.end,e=d.trim||b.findUri.trim,g=d.parens||b.findUri.parens,f=/[a-z0-9-]=["']?$/i;for(n.lastIndex=0;;){var h=n.exec(a);if(!h)break;var k=h.index;if(d.ignoreHtml){var p=a.slice(Math.max(k-3,0),k);if(p&&f.test(p))continue}for(var m=k+a.slice(k).search(l),p=a.slice(k,m),m=-1;;){var r=g.exec(p);if(!r)break;m=Math.max(m,r.index+r[0].length)}p=-1c))throw new TypeError('Port "'+a+'" is not a valid port');}};b.noConflict=function(a){if(a)return a={URI:this.noConflict()},k.URITemplate&&"function"===typeof k.URITemplate.noConflict&&(a.URITemplate=k.URITemplate.noConflict()),k.IPv6&&"function"===typeof k.IPv6.noConflict&& +""):p.replace(e,"");p.length<=h[0].length||d.ignore&&d.ignore.test(p)||(m=k+p.length,h=c(p,k,m,a),void 0===h?n.lastIndex=m:(h=String(h),a=a.slice(0,k)+h+a.slice(m),n.lastIndex=k+h.length))}n.lastIndex=0;return a};b.ensureValidHostname=function(a,c){var d=!!a,e=!1;c&&(e=p(b.hostProtocols,c));if(e&&!d)throw new TypeError("Hostname cannot be empty, if protocol is "+c);if(a&&a.match(b.invalid_hostname_characters)){if(!f)throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-:_] and Punycode.js is not available'); +if(f.toASCII(a).match(b.invalid_hostname_characters))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-:_]');}};b.ensureValidPort=function(a){if(a){var c=Number(a);if(!(/^[0-9]+$/.test(c)&&0c))throw new TypeError('Port "'+a+'" is not a valid port');}};b.noConflict=function(a){if(a)return a={URI:this.noConflict()},k.URITemplate&&"function"===typeof k.URITemplate.noConflict&&(a.URITemplate=k.URITemplate.noConflict()),k.IPv6&&"function"===typeof k.IPv6.noConflict&& (a.IPv6=k.IPv6.noConflict()),k.SecondLevelDomains&&"function"===typeof k.SecondLevelDomains.noConflict&&(a.SecondLevelDomains=k.SecondLevelDomains.noConflict()),a;k.URI===this&&(k.URI=w);return this};e.build=function(a){if(!0===a)this._deferred_build=!0;else if(void 0===a||this._deferred_build)this._string=b.build(this._parts),this._deferred_build=!1;return this};e.clone=function(){return new b(this)};e.valueOf=e.toString=function(){return this.build(!1)._string};e.protocol=r("protocol");e.username= r("username");e.password=r("password");e.hostname=r("hostname");e.port=r("port");e.query=C("query","?");e.fragment=C("fragment","#");e.search=function(a,c){var b=this.query(a,c);return"string"===typeof b&&b.length?"?"+b:b};e.hash=function(a,c){var b=this.fragment(a,c);return"string"===typeof b&&b.length?"#"+b:b};e.pathname=function(a,c){if(void 0===a||!0===a){var d=this._parts.path||(this._parts.hostname?"/":"");return a?(this._parts.urn?b.decodeUrnPath:b.decodePath)(d):d}this._parts.path=this._parts.urn? a?b.recodeUrnPath(a):"":a?b.recodePath(a):"/";this.build(!c);return this};e.path=e.pathname;e.href=function(a,c){var d;if(void 0===a)return this.toString();this._string="";this._parts=b._parts();var e=a instanceof b,l="object"===typeof a&&(a.hostname||a.path||a.pathname);a.nodeName&&(l=b.getDomAttribute(a),a=a[l]||"",l=!1);!e&&l&&void 0!==a.pathname&&(a=a.toString());if("string"===typeof a||a instanceof String)this._parts=b.parse(String(a),this._parts);else if(e||l)for(d in e=e?a._parts:a,e)t.call(this._parts, From 29ab10387b9d210c344302e4ce836f54157c9167 Mon Sep 17 00:00:00 2001 From: Chuan Zhang Date: Sun, 1 Oct 2017 20:22:53 +0800 Subject: [PATCH 29/44] feature(fragment-query): add setFragment() closes #338 * Add tests for static method URI.setQuery --- src/URI.fragmentQuery.js | 23 ++++++++++++++++++++--- src/URI.js | 15 +++++++++++++++ test/test.js | 38 ++++++++++++++++++++++++++++++++++++++ test/test_fragmentQuery.js | 32 ++++++++++++++++++++------------ 4 files changed, 93 insertions(+), 15 deletions(-) diff --git a/src/URI.fragmentQuery.js b/src/URI.fragmentQuery.js index 4a73441d..1b8391c8 100644 --- a/src/URI.fragmentQuery.js +++ b/src/URI.fragmentQuery.js @@ -19,6 +19,10 @@ // uri.toString() === "http://example.org/#?bar=foo&name=value"; // uri.removeFragment("name"); // uri.toString() === "http://example.org/#?bar=foo"; +// uri.setFragment("name", "value1"); +// uri.toString() === "http://example.org/#?bar=foo&name=value1"; +// uri.setFragment("name", "value2"); +// uri.toString() === "http://example.org/#?bar=foo&name=value2"; (function (root, factory) { 'use strict'; @@ -57,12 +61,12 @@ p.fragment = function(v, build) { var prefix = this._parts.fragmentPrefix; var fragment = this._parts.fragment || ''; - + if (v === true) { if (fragment.substring(0, prefix.length) !== prefix) { return {}; } - + return URI.parseQuery(fragment.substring(prefix.length)); } else if (v !== undefined && typeof v !== 'string') { this._parts.fragment = prefix + URI.buildQuery(v); @@ -96,9 +100,22 @@ this.build(!build); return this; }; + p.setFragment = function(name, value, build) { + var prefix = this._parts.fragmentPrefix; + var data = URI.parseQuery((this._parts.fragment || '').substring(prefix.length)); + URI.setQuery(data, name, value); + this._parts.fragment = prefix + URI.buildQuery(data); + if (typeof name !== 'string') { + build = value; + } + + this.build(!build); + return this; + }; p.addHash = p.addFragment; p.removeHash = p.removeFragment; + p.setHash = p.setFragment; // extending existing object rather than defining something new return URI; -})); \ No newline at end of file +})); diff --git a/src/URI.js b/src/URI.js index 47e6d9a7..0d659d61 100644 --- a/src/URI.js +++ b/src/URI.js @@ -780,6 +780,21 @@ throw new TypeError('URI.addQuery() accepts an object, string as the name parameter'); } }; + + URI.setQuery = function(data, name, value) { + if (typeof name === 'object') { + for (var key in name) { + if (hasOwn.call(name, key)) { + URI.setQuery(data, key, name[key]); + } + } + } else if (typeof name === 'string') { + data[name] = value === undefined ? null : value; + } else { + throw new TypeError('URI.setQuery() accepts an object, string as the name parameter'); + } + }; + URI.removeQuery = function(data, name, value) { var i, length, key; diff --git a/test/test.js b/test/test.js index d6efe220..385cf4ff 100644 --- a/test/test.js +++ b/test/test.js @@ -1792,6 +1792,44 @@ result = URI.joinPaths('a', '', '', 'b', '', '').toString(); equal(result, 'a/b/', 'trailing empty segment'); }); + test('setQuery', function () { + var o = {foo: 'bar'}; + + URI.setQuery(o, 'foo', 'bam'); + deepEqual(o, {foo: 'bam'}, 'set name, value'); + + URI.setQuery(o, 'array', ['one', 'two']); + deepEqual(o, {foo: 'bam', array: ['one', 'two']}, 'set name, array'); + + URI.setQuery(o, 'foo', 'qux'); + deepEqual(o, {foo: 'qux', array: ['one', 'two']}, 'override name, value'); + + o = {foo: 'bar'}; + URI.setQuery(o, {baz: 'qux'}); + deepEqual(o, {foo: 'bar', baz: 'qux'}, 'set {name: value}'); + + URI.setQuery(o, {bar: ['1', '2']}); + deepEqual(o, {foo: 'bar', bar: ['1', '2'], baz: 'qux'}, 'set {name: array}'); + + URI.setQuery(o, {foo: 'qux'}); + deepEqual(o, {foo: 'qux', bar: ['1', '2'], baz: 'qux'}, 'override {name: value}'); + + o = {foo: 'bar'}; + URI.setQuery(o, {bam: null, baz: ''}); + deepEqual(o, {foo: 'bar', bam: null, baz: ''}, 'set {name: null}'); + + o = {foo: 'bar'}; + URI.setQuery(o, 'empty'); + deepEqual(o, {foo: 'bar', empty: null}, 'set undefined'); + + o = {foo: 'bar'}; + URI.setQuery(o, 'empty', ''); + deepEqual(o, {foo: 'bar', empty: ''}, 'set empty string'); + + o = {}; + URI.setQuery(o, 'some value', 'must be encoded because of = and ? and #'); + deepEqual(o, {'some value': 'must be encoded because of = and ? and #'}, 'encoding'); + }); module('comparing URLs'); test('equals', function() { diff --git a/test/test_fragmentQuery.js b/test/test_fragmentQuery.js index a98406bf..7c4d5a4b 100644 --- a/test/test_fragmentQuery.js +++ b/test/test_fragmentQuery.js @@ -5,15 +5,15 @@ module('URI.fragmentQuery'); test('storing query-data in fragment', function() { var u = URI('http://example.org'); - + deepEqual(u.fragment(true), {}, 'empty map for missing fragment'); u = URI('http://example.org/#'); deepEqual(u.fragment(true), {}, 'empty map for empty fragment'); - + u = URI('http://example.org/#?hello=world'); deepEqual(u.fragment(true), {hello: 'world'}, 'reading data object'); - + u.fragment({bar: 'foo'}); deepEqual(u.fragment(true), {bar: 'foo'}, 'setting data object'); equal(u.toString(), 'http://example.org/#?bar=foo', 'setting data object serialized'); @@ -21,39 +21,47 @@ u.addFragment('name', 'value'); deepEqual(u.fragment(true), {bar: 'foo', name: 'value'}, 'adding value'); equal(u.toString(), 'http://example.org/#?bar=foo&name=value', 'adding value serialized'); - + u.removeFragment('bar'); deepEqual(u.fragment(true), {name: 'value'}, 'removing value bar'); equal(u.toString(), 'http://example.org/#?name=value', 'removing value bar serialized'); - + u.removeFragment('name'); deepEqual(u.fragment(true), {}, 'removing value name'); equal(u.toString(), 'http://example.org/#?', 'removing value name serialized'); + + u.setFragment('name', 'value1'); + deepEqual(u.fragment(true), {name: 'value1'}, 'setting name to value1'); + equal(u.toString(), 'http://example.org/#?name=value1', 'setting name to value1 serialized'); + + u.setFragment('name', 'value2'); + deepEqual(u.fragment(true), {name: 'value2'}, 'setting name to value2'); + equal(u.toString(), 'http://example.org/#?name=value2', 'setting name to value2 serialized'); }); test('fragmentPrefix', function() { var u; - + URI.fragmentPrefix = '!'; u = URI('http://example.org'); equal(u._parts.fragmentPrefix, '!', 'init using global property'); - + u.fragment('#?hello=world'); equal(u.fragment(), '?hello=world', 'unparsed ?'); deepEqual(u.fragment(true), {}, 'parsing ? prefix'); - + u.fragment('#!hello=world'); equal(u.fragment(), '!hello=world', 'unparsed !'); deepEqual(u.fragment(true), {hello: 'world'}, 'parsing ! prefix'); - + u.fragmentPrefix('§'); equal(u.fragment(), '!hello=world', 'unparsed §'); deepEqual(u.fragment(true), {}, 'parsing § prefix'); - + u.fragment('#§hello=world'); equal(u.fragment(), '§hello=world', 'unparsed §'); deepEqual(u.fragment(true), {hello: 'world'}, 'parsing § prefix'); - + URI.fragmentPrefix = '?'; }); -})(); \ No newline at end of file +})(); From d1cedf2368faf115a6252e9e4f8f5ddb4ee90b39 Mon Sep 17 00:00:00 2001 From: Rodney Rehm Date: Sun, 1 Oct 2017 14:55:38 +0200 Subject: [PATCH 30/44] fix(parse): add URI.preventInvalidHostname to make hostname validation optional - #345, 352, #354, #355 --- src/URI.js | 42 +++++++++++++++++++++++++++++++----------- test/test.js | 14 ++++++++++++++ test/test_jim.js | 4 ++-- 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/src/URI.js b/src/URI.js index 0d659d61..f896ff4b 100644 --- a/src/URI.js +++ b/src/URI.js @@ -201,10 +201,15 @@ query: null, fragment: null, // state + preventInvalidHostname: URI.preventInvalidHostname, duplicateQueryParameters: URI.duplicateQueryParameters, escapeQuerySpace: URI.escapeQuerySpace }; }; + // state: throw on invalid hostname + // see https://github.com/medialize/URI.js/pull/345 + // and https://github.com/medialize/URI.js/issues/354 + URI.preventInvalidHostname = false; // state: allow duplicate query parameters (a=1&a=1) URI.duplicateQueryParameters = false; // state: replaces + with %20 (space in query strings) @@ -485,7 +490,9 @@ URI.parse = function(string, parts) { var pos; if (!parts) { - parts = {}; + parts = { + preventInvalidHostname: URI.preventInvalidHostname + }; } // [protocol"://"[username[":"password]"@"]hostname[":"port]"/"?][path]["?"querystring]["#"fragment] @@ -538,6 +545,10 @@ return parts; }; URI.parseHost = function(string, parts) { + if (!string) { + string = ''; + } + // Copy chrome, IE, opera backslash-handling behavior. // Back slashes before the query string get converted to forward slashes // See: https://github.com/joyent/node/blob/386fd24f49b0e9d1a8a076592a404168faeecc34/lib/url.js#L115-L124 @@ -585,7 +596,9 @@ string = '/' + string; } - URI.ensureValidHostname(parts.hostname, parts.protocol); + if (parts.preventInvalidHostname) { + URI.ensureValidHostname(parts.hostname, parts.protocol); + } if (parts.port) { URI.ensureValidPort(parts.port); @@ -1312,16 +1325,15 @@ var _hostname = p.hostname; p.protocol = function(v, build) { - if (v !== undefined) { - if (v) { - // accept trailing :// - v = v.replace(/:(\/\/)?$/, ''); + if (v) { + // accept trailing :// + v = v.replace(/:(\/\/)?$/, ''); - if (!v.match(URI.protocol_expression)) { - throw new TypeError('Protocol "' + v + '" contains characters other than [A-Z0-9.+-] or doesn\'t start with [A-Z]'); - } + if (!v.match(URI.protocol_expression)) { + throw new TypeError('Protocol "' + v + '" contains characters other than [A-Z0-9.+-] or doesn\'t start with [A-Z]'); } } + return _protocol.call(this, v, build); }; p.scheme = p.protocol; @@ -1352,15 +1364,18 @@ } if (v !== undefined) { - var x = {}; + var x = { preventInvalidHostname: this._parts.preventInvalidHostname }; var res = URI.parseHost(v, x); if (res !== '/') { throw new TypeError('Hostname "' + v + '" contains characters other than [A-Z0-9.-]'); } v = x.hostname; - URI.ensureValidHostname(v, this._parts.protocol); + if (this._parts.preventInvalidHostname) { + URI.ensureValidHostname(v, this._parts.protocol); + } } + return _hostname.call(this, v, build); }; @@ -2300,6 +2315,11 @@ }; // state + p.preventInvalidHostname = function(v) { + this._parts.preventInvalidHostname = !!v; + return this; + }; + p.duplicateQueryParameters = function(v) { this._parts.duplicateQueryParameters = !!v; return this; diff --git a/test/test.js b/test/test.js index 385cf4ff..fe62c01c 100644 --- a/test/test.js +++ b/test/test.js @@ -140,9 +140,15 @@ }, TypeError, "throws TypeError"); }); test('function URI(string) with protocol and without hostname should throw', function () { + new URI('http://'); + + URI.preventInvalidHostname = true; raises(function () { new URI('http://'); }, TypeError, "throws TypeError"); + + URI.preventInvalidHostname = false; + new URI('http://'); }); test('new URI(string, string)', function() { // see http://dvcs.w3.org/hg/url/raw-file/tip/Overview.html#constructor @@ -251,9 +257,17 @@ u.hostname('foo\\bar.com'); }, TypeError, 'Failing backslash detection in hostname'); + // instance does not fall back to global setting + URI.preventInvalidHostname = true; + u.hostname(''); + u.hostname(null); + URI.preventInvalidHostname = false; + + u.preventInvalidHostname(true); raises(function() { u.hostname(''); }, TypeError, "Trying to set an empty hostname with http(s) protocol throws a TypeError"); + raises(function() { u.hostname(null); }, TypeError, "Trying to set hostname to null with http(s) protocol throws a TypeError"); diff --git a/test/test_jim.js b/test/test_jim.js index 86204c29..cdb27624 100644 --- a/test/test_jim.js +++ b/test/test_jim.js @@ -146,7 +146,7 @@ domain = "com"; for (j=0; j<3; j++) { //start new subdomain - domain = "." + domain; + domain = "." + domain; for (i=0; i<70; i++) { domain = "a" + domain; } @@ -155,4 +155,4 @@ equals(u.hostname() == domain, true, "set domain() with 70-character subdomain not valid domainname"); }); */ -})(); \ No newline at end of file +})(); From 3cc5c22dc7d699e16101cf4277347b7389d2e271 Mon Sep 17 00:00:00 2001 From: Rodney Rehm Date: Sun, 1 Oct 2017 15:06:59 +0200 Subject: [PATCH 31/44] chore(build): bumping to version 1.19.0 --- CHANGELOG.md | 5 +++++ bower.json | 2 +- build.js | 2 +- docs.html | 11 +++++++++++ package.json | 2 +- src/IPv6.js | 2 +- src/SecondLevelDomains.js | 2 +- src/URI.js | 4 ++-- src/URITemplate.js | 2 +- src/jquery.URI.js | 2 +- 10 files changed, 25 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index caf7b0f8..3a90344a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ The release notes tracked in this document are also made available on the [releases page](https://github.com/medialize/URI.js/releases) +### 1.19.0 (October 1st 2017) ### + +* adding `.setFragment()` to [query fragment plugin](http://medialize.github.io/URI.js/docs.html#fragment-abuse-query) - [Issue #338](https://github.com/medialize/URI.js/issues/338), [PR #356](https://github.com/medialize/URI.js/issues/356) +* adding setting [`URI.preventInvalidHostname`](http://medialize.github.io/URI.js/docs.html#setting-preventInvalidHostname) to control if an error should be thrown on invalid input - [Issue #352](https://github.com/medialize/URI.js/issues/352), [Issue #354](https://github.com/medialize/URI.js/issues/354), [Issue #355](https://github.com/medialize/URI.js/issues/355) - effectively making the changes of version 1.18.11 opt-in rather than default. + ### 1.18.12 (August 9th 2017) ### * making [`URI.parse()`](http://medialize.github.io/URI.js/docs.html#static-parse) allow `_` in hostname - [Issue #347](https://github.com/medialize/URI.js/issues/347), [PR #348](https://github.com/medialize/URI.js/issues/348) diff --git a/bower.json b/bower.json index c282151f..5a4b37dd 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "urijs", - "version": "1.18.12", + "version": "1.19.0", "main": "src/URI.js", "ignore": [ ".*", diff --git a/build.js b/build.js index 9b8ca747..c17a8d31 100644 --- a/build.js +++ b/build.js @@ -29,7 +29,7 @@ function build(files) { output_format: "text", output_info: "compiled_code" }, function(data) { - var code = "/*! URI.js v1.18.12 http://medialize.github.io/URI.js/ */\n/* build contains: " + files.join(', ') + " */\n" + data; + var code = "/*! URI.js v1.19.0 http://medialize.github.io/URI.js/ */\n/* build contains: " + files.join(', ') + " */\n" + data; $progress.hide(); $out.val(code).parent().show(); $out.prev().find('a').remove(); diff --git a/docs.html b/docs.html index cd955180..2feb9e43 100644 --- a/docs.html +++ b/docs.html @@ -1037,6 +1037,17 @@

URI.parseHost(string url, object par hostname: "example.org", port: "8080" }; +

As of v1.19.0 you can activate host name validation (disabled by default):

+
URI.preventInvalidHostname = true;
+var parts = {};
+var result = URI.parseHost("/foo.html", parts);
+// throws TypeError
+
+URI.preventInvalidHostname = false;
+var uri = new URI('http://example.org/')
+  .preventInvalidHostname(true)
+  .hostname('')
+// throws TypeError

URI.parseQuery(string querystring)

Parses the passed query string into an object. Returns object {propertyName: propertyValue}

diff --git a/package.json b/package.json index 67b1e2fc..2998baee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "urijs", - "version": "1.18.12", + "version": "1.19.0", "title": "URI.js - Mutating URLs", "author": { "name": "Rodney Rehm", diff --git a/src/IPv6.js b/src/IPv6.js index 5fbf3a18..5f389450 100644 --- a/src/IPv6.js +++ b/src/IPv6.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * IPv6 Support * - * Version: 1.18.12 + * Version: 1.19.0 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/SecondLevelDomains.js b/src/SecondLevelDomains.js index da6d1a31..e926a05b 100644 --- a/src/SecondLevelDomains.js +++ b/src/SecondLevelDomains.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * Second Level Domain (SLD) Support * - * Version: 1.18.12 + * Version: 1.19.0 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/URI.js b/src/URI.js index f896ff4b..1d7957a0 100644 --- a/src/URI.js +++ b/src/URI.js @@ -1,7 +1,7 @@ /*! * URI.js - Mutating URLs * - * Version: 1.18.12 + * Version: 1.19.0 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ @@ -81,7 +81,7 @@ return /^[0-9]+$/.test(value); } - URI.version = '1.18.12'; + URI.version = '1.19.0'; var p = URI.prototype; var hasOwn = Object.prototype.hasOwnProperty; diff --git a/src/URITemplate.js b/src/URITemplate.js index b59f1481..36989cc2 100644 --- a/src/URITemplate.js +++ b/src/URITemplate.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * URI Template Support - http://tools.ietf.org/html/rfc6570 * - * Version: 1.18.12 + * Version: 1.19.0 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/jquery.URI.js b/src/jquery.URI.js index e56465ce..6b89e57a 100644 --- a/src/jquery.URI.js +++ b/src/jquery.URI.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * jQuery Plugin * - * Version: 1.18.12 + * Version: 1.19.0 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/jquery-uri-plugin.html From fde82ec36c9ac99b053582f19fa051dad8ae37d5 Mon Sep 17 00:00:00 2001 From: Rodney Rehm Date: Sun, 1 Oct 2017 15:09:46 +0200 Subject: [PATCH 32/44] chore(build): bumping to version 1.19.0 --- src/URI.min.js | 130 +++++++++++++++++++++--------------------- src/jquery.URI.min.js | 2 +- 2 files changed, 67 insertions(+), 65 deletions(-) diff --git a/src/URI.min.js b/src/URI.min.js index 91755685..5386babf 100644 --- a/src/URI.min.js +++ b/src/URI.min.js @@ -1,14 +1,14 @@ -/*! URI.js v1.18.12 http://medialize.github.io/URI.js/ */ +/*! URI.js v1.19.0 http://medialize.github.io/URI.js/ */ /* build contains: IPv6.js, punycode.js, SecondLevelDomains.js, URI.js, URITemplate.js */ -(function(f,m){"object"===typeof module&&module.exports?module.exports=m():"function"===typeof define&&define.amd?define(m):f.IPv6=m(f)})(this,function(f){var m=f&&f.IPv6;return{best:function(h){h=h.toLowerCase().split(":");var k=h.length,b=8;""===h[0]&&""===h[1]&&""===h[2]?(h.shift(),h.shift()):""===h[0]&&""===h[1]?h.shift():""===h[k-1]&&""===h[k-2]&&h.pop();k=h.length;-1!==h[k-1].indexOf(".")&&(b=7);var q;for(q=0;qf;f++)if("0"===k[0]&&1f&&(k=g,f=m)):"0"===h[q]&&(p=!0,g=q,m=1);m>f&&(k=g,f=m);1=f&&g>>10&1023|55296),b=56320|b&1023);return e+=t(b)}).join("")}function z(b,e){return b+22+75*(26>b)-((0!=e)<<5)}function u(b,g,h){var f=0;b=h?e(b/700):b>>1;for(b+=e(b/g);455n&&(n=0);for(c=0;c=h&&m("invalid-input");var x=b.charCodeAt(n++); -x=10>x-48?x-22:26>x-65?x-65:26>x-97?x-97:36;(36<=x||x>e((2147483647-f)/l))&&m("overflow");f+=x*l;var p=d<=a?1:d>=a+26?26:d-a;if(xe(2147483647/x)&&m("overflow");l*=x}l=g.length+1;a=u(f-c,l,0==c);e(f/l)>2147483647-k&&m("overflow");k+=e(f/l);f%=l;g.splice(f++,0,k)}return q(g)}function p(g){var h,f,k,p=[];g=b(g);var a=g.length;var c=128;var d=0;var n=72;for(k=0;kl&&p.push(t(l))}for((h=f=p.length)&&p.push("-");h=c&& -le((2147483647-d)/q)&&m("overflow");d+=(x-c)*q;c=x;for(k=0;k=n+26?26:x-n;if(rf;f++)if("0"===k[0]&&1f&&(k=g,f=n)):"0"===h[q]&&(p=!0,g=q,n=1);n>f&&(k=g,f=n);1=f&&g>>10&1023|55296),b=56320|b&1023);return e+=t(b)}).join("")}function z(b,e){return b+22+75*(26>b)-((0!=e)<<5)}function u(b,g,h){var f=0;b=h?e(b/700):b>>1;for(b+=e(b/g);455l&&(l=0);for(c=0;c=h&&n("invalid-input");var x=b.charCodeAt(l++); +x=10>x-48?x-22:26>x-65?x-65:26>x-97?x-97:36;(36<=x||x>e((2147483647-f)/m))&&n("overflow");f+=x*m;var p=d<=a?1:d>=a+26?26:d-a;if(xe(2147483647/x)&&n("overflow");m*=x}m=g.length+1;a=u(f-c,m,0==c);e(f/m)>2147483647-k&&n("overflow");k+=e(f/m);f%=m;g.splice(f++,0,k)}return q(g)}function p(g){var h,f,k,p=[];g=b(g);var a=g.length;var c=128;var d=0;var l=72;for(k=0;km&&p.push(t(m))}for((h=f=p.length)&&p.push("-");h=c&& +me((2147483647-d)/q)&&n("overflow");d+=(x-c)*q;c=x;for(k=0;k=l+26?26:x-l;if(r= 0x80 (not a basic code point)","invalid-input":"Invalid input"},e=Math.floor,t=String.fromCharCode,y;var v={version:"1.3.2",ucs2:{decode:b,encode:q},decode:g,encode:p,toASCII:function(b){return k(b,function(b){return r.test(b)?"xn--"+p(b):b})},toUnicode:function(b){return k(b,function(b){return E.test(b)?g(b.slice(4).toLowerCase()): b})}};if("function"==typeof define&&"object"==typeof define.amd&&define.amd)define("punycode",function(){return v});else if(D&&A)if(module.exports==D)A.exports=v;else for(y in v)v.hasOwnProperty(y)&&(D[y]=v[y]);else f.punycode=v})(this); -(function(f,m){"object"===typeof module&&module.exports?module.exports=m():"function"===typeof define&&define.amd?define(m):f.SecondLevelDomains=m(f)})(this,function(f){var m=f&&f.SecondLevelDomains,h={list:{ac:" com gov mil net org ",ae:" ac co gov mil name net org pro sch ",af:" com edu gov net org ",al:" com edu gov mil net org ",ao:" co ed gv it og pb ",ar:" com edu gob gov int mil net org tur ",at:" ac co gv or ",au:" asn com csiro edu gov id net org ",ba:" co com edu gov mil net org rs unbi unmo unsa untz unze ", +(function(f,n){"object"===typeof module&&module.exports?module.exports=n():"function"===typeof define&&define.amd?define(n):f.SecondLevelDomains=n(f)})(this,function(f){var n=f&&f.SecondLevelDomains,h={list:{ac:" com gov mil net org ",ae:" ac co gov mil name net org pro sch ",af:" com edu gov net org ",al:" com edu gov mil net org ",ao:" co ed gv it og pb ",ar:" com edu gob gov int mil net org tur ",at:" ac co gv or ",au:" asn com csiro edu gov id net org ",ba:" co com edu gov mil net org rs unbi unmo unsa untz unze ", bb:" biz co com edu gov info net org store tv ",bh:" biz cc com edu gov info net org ",bn:" com edu gov net org ",bo:" com edu gob gov int mil net org tv ",br:" adm adv agr am arq art ato b bio blog bmd cim cng cnt com coop ecn edu eng esp etc eti far flog fm fnd fot fst g12 ggf gov imb ind inf jor jus lel mat med mil mus net nom not ntr odo org ppg pro psc psi qsl rec slg srv tmp trd tur tv vet vlog wiki zlg ",bs:" com edu gov net org ",bz:" du et om ov rg ",ca:" ab bc mb nb nf nl ns nt nu on pe qc sk yk ", ck:" biz co edu gen gov info net org ",cn:" ac ah bj com cq edu fj gd gov gs gx gz ha hb he hi hl hn jl js jx ln mil net nm nx org qh sc sd sh sn sx tj tw xj xz yn zj ",co:" com edu gov mil net nom org ",cr:" ac c co ed fi go or sa ",cy:" ac biz com ekloges gov ltd name net org parliament press pro tm ","do":" art com edu gob gov mil net org sld web ",dz:" art asso com edu gov net org pol ",ec:" com edu fin gov info med mil net org pro ",eg:" com edu eun gov mil name net org sci ",er:" com edu gov ind mil net org rochest w ", es:" com edu gob nom org ",et:" biz com edu gov info name net org ",fj:" ac biz com info mil name net org pro ",fk:" ac co gov net nom org ",fr:" asso com f gouv nom prd presse tm ",gg:" co net org ",gh:" com edu gov mil org ",gn:" ac com gov net org ",gr:" com edu gov mil net org ",gt:" com edu gob ind mil net org ",gu:" com edu gov net org ",hk:" com edu gov idv net org ",hu:" 2000 agrar bolt casino city co erotica erotika film forum games hotel info ingatlan jogasz konyvelo lakas media news org priv reklam sex shop sport suli szex tm tozsde utazas video ", @@ -21,71 +21,73 @@ tw:" club com ebiz edu game gov idv mil net org ",mu:" ac co com gov net or org rw:" ac co com edu gouv gov int mil net ",sa:" com edu gov med net org pub sch ",sd:" com edu gov info med net org tv ",se:" a ac b bd c d e f g h i k l m n o org p parti pp press r s t tm u w x y z ",sg:" com edu gov idn net org per ",sn:" art com edu gouv org perso univ ",sy:" com edu gov mil net news org ",th:" ac co go in mi net or ",tj:" ac biz co com edu go gov info int mil name net nic org test web ",tn:" agrinet com defense edunet ens fin gov ind info intl mincom nat net org perso rnrt rns rnu tourism ", tz:" ac co go ne or ",ua:" biz cherkassy chernigov chernovtsy ck cn co com crimea cv dn dnepropetrovsk donetsk dp edu gov if in ivano-frankivsk kh kharkov kherson khmelnitskiy kiev kirovograd km kr ks kv lg lugansk lutsk lviv me mk net nikolaev od odessa org pl poltava pp rovno rv sebastopol sumy te ternopil uzhgorod vinnica vn zaporizhzhe zhitomir zp zt ",ug:" ac co go ne or org sc ",uk:" ac bl british-library co cym gov govt icnet jet lea ltd me mil mod national-library-scotland nel net nhs nic nls org orgn parliament plc police sch scot soc ", us:" dni fed isa kids nsn ",uy:" com edu gub mil net org ",ve:" co com edu gob info mil net org web ",vi:" co com k12 net org ",vn:" ac biz com edu gov health info int name net org pro ",ye:" co com gov ltd me net org plc ",yu:" ac co edu gov org ",za:" ac agric alt bourse city co cybernet db edu gov grondar iaccess imt inca landesign law mil net ngo nis nom olivetti org pix school tm web ",zm:" ac co com edu gov net org sch ",com:"ar br cn de eu gb gr hu jpn kr no qc ru sa se uk us uy za ",net:"gb jp se uk ", -org:"ae",de:"com "},has:function(f){var b=f.lastIndexOf(".");if(0>=b||b>=f.length-1)return!1;var k=f.lastIndexOf(".",b-1);if(0>=k||k>=b-1)return!1;var m=h.list[f.slice(b+1)];return m?0<=m.indexOf(" "+f.slice(k+1,b)+" "):!1},is:function(f){var b=f.lastIndexOf(".");if(0>=b||b>=f.length-1||0<=f.lastIndexOf(".",b-1))return!1;var k=h.list[f.slice(b+1)];return k?0<=k.indexOf(" "+f.slice(0,b)+" "):!1},get:function(f){var b=f.lastIndexOf(".");if(0>=b||b>=f.length-1)return null;var k=f.lastIndexOf(".",b-1); -if(0>=k||k>=b-1)return null;var m=h.list[f.slice(b+1)];return!m||0>m.indexOf(" "+f.slice(k+1,b)+" ")?null:f.slice(k+1)},noConflict:function(){f.SecondLevelDomains===this&&(f.SecondLevelDomains=m);return this}};return h}); -(function(f,m){"object"===typeof module&&module.exports?module.exports=m(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"===typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],m):f.URI=m(f.punycode,f.IPv6,f.SecondLevelDomains,f)})(this,function(f,m,h,k){function b(a,c){var d=1<=arguments.length,n=2<=arguments.length;if(!(this instanceof b))return d?n?new b(a,c):new b(a):new b;if(void 0===a){if(d)throw new TypeError("undefined is not a valid argument for URI"); -a="undefined"!==typeof location?location.href+"":""}if(null===a&&d)throw new TypeError("null is not a valid argument for URI");this.href(a);return void 0!==c?this.absoluteTo(c):this}function q(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function z(a){return void 0===a?"Undefined":String(Object.prototype.toString.call(a)).slice(8,-1)}function u(a){return"Array"===z(a)}function g(a,c){var d={},b;if("RegExp"===z(c))d=null;else if(u(c)){var l=0;for(b=c.length;l=b||b>=f.length-1)return!1;var k=f.lastIndexOf(".",b-1);if(0>=k||k>=b-1)return!1;var n=h.list[f.slice(b+1)];return n?0<=n.indexOf(" "+f.slice(k+1,b)+" "):!1},is:function(f){var b=f.lastIndexOf(".");if(0>=b||b>=f.length-1||0<=f.lastIndexOf(".",b-1))return!1;var k=h.list[f.slice(b+1)];return k?0<=k.indexOf(" "+f.slice(0,b)+" "):!1},get:function(f){var b=f.lastIndexOf(".");if(0>=b||b>=f.length-1)return null;var k=f.lastIndexOf(".",b-1); +if(0>=k||k>=b-1)return null;var n=h.list[f.slice(b+1)];return!n||0>n.indexOf(" "+f.slice(k+1,b)+" ")?null:f.slice(k+1)},noConflict:function(){f.SecondLevelDomains===this&&(f.SecondLevelDomains=n);return this}};return h}); +(function(f,n){"object"===typeof module&&module.exports?module.exports=n(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"===typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],n):f.URI=n(f.punycode,f.IPv6,f.SecondLevelDomains,f)})(this,function(f,n,h,k){function b(a,c){var d=1<=arguments.length,l=2<=arguments.length;if(!(this instanceof b))return d?l?new b(a,c):new b(a):new b;if(void 0===a){if(d)throw new TypeError("undefined is not a valid argument for URI"); +a="undefined"!==typeof location?location.href+"":""}if(null===a&&d)throw new TypeError("null is not a valid argument for URI");this.href(a);return void 0!==c?this.absoluteTo(c):this}function q(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function z(a){return void 0===a?"Undefined":String(Object.prototype.toString.call(a)).slice(8,-1)}function u(a){return"Array"===z(a)}function g(a,c){var d={},b;if("RegExp"===z(c))d=null;else if(u(c)){var m=0;for(b=c.length;m]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u2018\u2019]))/ig;b.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u201e\u2018\u2019]+$/,parens:/(\([^\)]*\)|\[[^\]]*\]|\{[^}]*\}|<[^>]*>)/g};b.defaultPorts={http:"80",https:"443",ftp:"21", gopher:"70",ws:"80",wss:"443"};b.hostProtocols=["http","https"];b.invalid_hostname_characters=/[^a-zA-Z0-9\.\-:_]/;b.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src",audio:"src",video:"src"};b.getDomAttribute=function(a){if(a&&a.nodeName){var c=a.nodeName.toLowerCase();if("input"!==c||"image"===a.type)return b.domAttributes[c]}};b.encode=E;b.decode=decodeURIComponent;b.iso8859= function(){b.encode=escape;b.decode=unescape};b.unicode=function(){b.encode=E;b.decode=decodeURIComponent};b.characters={pathname:{encode:{expression:/%(24|26|2B|2C|3B|3D|3A|40)/ig,map:{"%24":"$","%26":"&","%2B":"+","%2C":",","%3B":";","%3D":"=","%3A":":","%40":"@"}},decode:{expression:/[\/\?#]/g,map:{"/":"%2F","?":"%3F","#":"%23"}}},reserved:{encode:{expression:/%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/ig,map:{"%3A":":","%2F":"/","%3F":"?","%23":"#","%5B":"[","%5D":"]","%40":"@", "%21":"!","%24":"$","%26":"&","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"="}}},urnpath:{encode:{expression:/%(21|24|27|28|29|2A|2B|2C|3B|3D|40)/ig,map:{"%21":"!","%24":"$","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"=","%40":"@"}},decode:{expression:/[\/\?#:]/g,map:{"/":"%2F","?":"%3F","#":"%23",":":"%3A"}}}};b.encodeQuery=function(a,c){var d=b.encode(a+"");void 0===c&&(c=b.escapeQuerySpace);return c?d.replace(/%20/g,"+"):d};b.decodeQuery= -function(a,c){a+="";void 0===c&&(c=b.escapeQuerySpace);try{return b.decode(c?a.replace(/\+/g,"%20"):a)}catch(d){return a}};var y={encode:"encode",decode:"decode"},v,F=function(a,c){return function(d){try{return b[c](d+"").replace(b.characters[a][c].expression,function(d){return b.characters[a][c].map[d]})}catch(n){return d}}};for(v in y)b[v+"PathSegment"]=F("pathname",y[v]),b[v+"UrnPathSegment"]=F("urnpath",y[v]);y=function(a,c,d){return function(n){var l=d?function(a){return b[c](b[d](a))}:b[c]; -n=(n+"").split(a);for(var e=0,g=n.length;eb)return a.charAt(0)===c.charAt(0)&&"/"===a.charAt(0)?"/":"";if("/"!==a.charAt(b)||"/"!==c.charAt(b))b=a.substring(0, -b).lastIndexOf("/");return a.substring(0,b+1)};b.withinString=function(a,c,d){d||(d={});var n=d.start||b.findUri.start,l=d.end||b.findUri.end,e=d.trim||b.findUri.trim,g=d.parens||b.findUri.parens,f=/[a-z0-9-]=["']?$/i;for(n.lastIndex=0;;){var h=n.exec(a);if(!h)break;var k=h.index;if(d.ignoreHtml){var p=a.slice(Math.max(k-3,0),k);if(p&&f.test(p))continue}for(var m=k+a.slice(k).search(l),p=a.slice(k,m),m=-1;;){var r=g.exec(p);if(!r)break;m=Math.max(m,r.index+r[0].length)}p=-1c))throw new TypeError('Port "'+a+'" is not a valid port');}};b.noConflict=function(a){if(a)return a={URI:this.noConflict()},k.URITemplate&&"function"===typeof k.URITemplate.noConflict&&(a.URITemplate=k.URITemplate.noConflict()),k.IPv6&&"function"===typeof k.IPv6.noConflict&& -(a.IPv6=k.IPv6.noConflict()),k.SecondLevelDomains&&"function"===typeof k.SecondLevelDomains.noConflict&&(a.SecondLevelDomains=k.SecondLevelDomains.noConflict()),a;k.URI===this&&(k.URI=w);return this};e.build=function(a){if(!0===a)this._deferred_build=!0;else if(void 0===a||this._deferred_build)this._string=b.build(this._parts),this._deferred_build=!1;return this};e.clone=function(){return new b(this)};e.valueOf=e.toString=function(){return this.build(!1)._string};e.protocol=r("protocol");e.username= -r("username");e.password=r("password");e.hostname=r("hostname");e.port=r("port");e.query=C("query","?");e.fragment=C("fragment","#");e.search=function(a,c){var b=this.query(a,c);return"string"===typeof b&&b.length?"?"+b:b};e.hash=function(a,c){var b=this.fragment(a,c);return"string"===typeof b&&b.length?"#"+b:b};e.pathname=function(a,c){if(void 0===a||!0===a){var d=this._parts.path||(this._parts.hostname?"/":"");return a?(this._parts.urn?b.decodeUrnPath:b.decodePath)(d):d}this._parts.path=this._parts.urn? -a?b.recodeUrnPath(a):"":a?b.recodePath(a):"/";this.build(!c);return this};e.path=e.pathname;e.href=function(a,c){var d;if(void 0===a)return this.toString();this._string="";this._parts=b._parts();var e=a instanceof b,l="object"===typeof a&&(a.hostname||a.path||a.pathname);a.nodeName&&(l=b.getDomAttribute(a),a=a[l]||"",l=!1);!e&&l&&void 0!==a.pathname&&(a=a.toString());if("string"===typeof a||a instanceof String)this._parts=b.parse(String(a),this._parts);else if(e||l)for(d in e=e?a._parts:a,e)t.call(this._parts, -d)&&(this._parts[d]=e[d]);else throw new TypeError("invalid input");this.build(!c);return this};e.is=function(a){var c=!1,d=!1,e=!1,l=!1,g=!1,f=!1,k=!1,p=!this._parts.urn;this._parts.hostname&&(p=!1,d=b.ip4_expression.test(this._parts.hostname),e=b.ip6_expression.test(this._parts.hostname),c=d||e,g=(l=!c)&&h&&h.has(this._parts.hostname),f=l&&b.idn_expression.test(this._parts.hostname),k=l&&b.punycode_expression.test(this._parts.hostname));switch(a.toLowerCase()){case "relative":return p;case "absolute":return!p; -case "domain":case "name":return l;case "sld":return g;case "ip":return c;case "ip4":case "ipv4":case "inet4":return d;case "ip6":case "ipv6":case "inet6":return e;case "idn":return f;case "url":return!this._parts.urn;case "urn":return!!this._parts.urn;case "punycode":return k}return null};var G=e.protocol,H=e.port,I=e.hostname;e.protocol=function(a,c){if(void 0!==a&&a&&(a=a.replace(/:(\/\/)?$/,""),!a.match(b.protocol_expression)))throw new TypeError('Protocol "'+a+"\" contains characters other than [A-Z0-9.+-] or doesn't start with [A-Z]"); -return G.call(this,a,c)};e.scheme=e.protocol;e.port=function(a,c){if(this._parts.urn)return void 0===a?"":this;void 0!==a&&(0===a&&(a=null),a&&(a+="",":"===a.charAt(0)&&(a=a.substring(1)),b.ensureValidPort(a)));return H.call(this,a,c)};e.hostname=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0!==a){var d={};if("/"!==b.parseHost(a,d))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]');a=d.hostname;b.ensureValidHostname(a,this._parts.protocol)}return I.call(this, -a,c)};e.origin=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){var d=this.protocol();return this.authority()?(d?d+"://":"")+this.authority():""}d=b(a);this.protocol(d.protocol()).authority(d.authority()).build(!c);return this};e.host=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a)return this._parts.hostname?b.buildHost(this._parts):"";if("/"!==b.parseHost(a,this._parts))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]'); -this.build(!c);return this};e.authority=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a)return this._parts.hostname?b.buildAuthority(this._parts):"";if("/"!==b.parseAuthority(a,this._parts))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]');this.build(!c);return this};e.userinfo=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){var d=b.buildUserinfo(this._parts);return d?d.substring(0,d.length-1):d}"@"!==a[a.length-1]&& -(a+="@");b.parseUserinfo(a,this._parts);this.build(!c);return this};e.resource=function(a,c){if(void 0===a)return this.path()+this.search()+this.hash();var d=b.parse(a);this._parts.path=d.path;this._parts.query=d.query;this._parts.fragment=d.fragment;this.build(!c);return this};e.subdomain=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var d=this._parts.hostname.length-this.domain().length-1;return this._parts.hostname.substring(0, -d)||""}d=this._parts.hostname.length-this.domain().length;d=this._parts.hostname.substring(0,d);d=new RegExp("^"+q(d));a&&"."!==a.charAt(a.length-1)&&(a+=".");if(-1!==a.indexOf(":"))throw new TypeError("Domains cannot contain colons");a&&b.ensureValidHostname(a,this._parts.protocol);this._parts.hostname=this._parts.hostname.replace(d,a);this.build(!c);return this};e.domain=function(a,c){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(c=a,a=void 0);if(void 0===a){if(!this._parts.hostname|| -this.is("IP"))return"";var d=this._parts.hostname.match(/\./g);if(d&&2>d.length)return this._parts.hostname;d=this._parts.hostname.length-this.tld(c).length-1;d=this._parts.hostname.lastIndexOf(".",d-1)+1;return this._parts.hostname.substring(d)||""}if(!a)throw new TypeError("cannot set domain empty");if(-1!==a.indexOf(":"))throw new TypeError("Domains cannot contain colons");b.ensureValidHostname(a,this._parts.protocol);!this._parts.hostname||this.is("IP")?this._parts.hostname=a:(d=new RegExp(q(this.domain())+ -"$"),this._parts.hostname=this._parts.hostname.replace(d,a));this.build(!c);return this};e.tld=function(a,c){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(c=a,a=void 0);if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var b=this._parts.hostname.lastIndexOf("."),b=this._parts.hostname.substring(b+1);return!0!==c&&h&&h.list[b.toLowerCase()]?h.get(this._parts.hostname)||b:b}if(a)if(a.match(/[^a-zA-Z0-9-]/))if(h&&h.is(a))b=new RegExp(q(this.tld())+"$"),this._parts.hostname= -this._parts.hostname.replace(b,a);else throw new TypeError('TLD "'+a+'" contains characters other than [A-Z0-9]');else{if(!this._parts.hostname||this.is("IP"))throw new ReferenceError("cannot set TLD on non-domain host");b=new RegExp(q(this.tld())+"$");this._parts.hostname=this._parts.hostname.replace(b,a)}else throw new TypeError("cannot set TLD empty");this.build(!c);return this};e.directory=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path&& -!this._parts.hostname)return"";if("/"===this._parts.path)return"/";var d=this._parts.path.length-this.filename().length-1,d=this._parts.path.substring(0,d)||(this._parts.hostname?"/":"");return a?b.decodePath(d):d}d=this._parts.path.length-this.filename().length;d=this._parts.path.substring(0,d);d=new RegExp("^"+q(d));this.is("relative")||(a||(a="/"),"/"!==a.charAt(0)&&(a="/"+a));a&&"/"!==a.charAt(a.length-1)&&(a+="/");a=b.recodePath(a);this._parts.path=this._parts.path.replace(d,a);this.build(!c); -return this};e.filename=function(a,c){if(this._parts.urn)return void 0===a?"":this;if("string"!==typeof a){if(!this._parts.path||"/"===this._parts.path)return"";var d=this._parts.path.lastIndexOf("/"),d=this._parts.path.substring(d+1);return a?b.decodePathSegment(d):d}d=!1;"/"===a.charAt(0)&&(a=a.substring(1));a.match(/\.?\//)&&(d=!0);var e=new RegExp(q(this.filename())+"$");a=b.recodePath(a);this._parts.path=this._parts.path.replace(e,a);d?this.normalizePath(c):this.build(!c);return this};e.suffix= -function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path||"/"===this._parts.path)return"";var d=this.filename(),e=d.lastIndexOf(".");if(-1===e)return"";d=d.substring(e+1);d=/^[a-z0-9%]+$/i.test(d)?d:"";return a?b.decodePathSegment(d):d}"."===a.charAt(0)&&(a=a.substring(1));if(d=this.suffix())e=a?new RegExp(q(d)+"$"):new RegExp(q("."+d)+"$");else{if(!a)return this;this._parts.path+="."+b.recodePath(a)}e&&(a=b.recodePath(a),this._parts.path=this._parts.path.replace(e, -a));this.build(!c);return this};e.segment=function(a,c,b){var d=this._parts.urn?":":"/",e=this.path(),g="/"===e.substring(0,1),e=e.split(d);void 0!==a&&"number"!==typeof a&&(b=c,c=a,a=void 0);if(void 0!==a&&"number"!==typeof a)throw Error('Bad segment "'+a+'", must be 0-based integer');g&&e.shift();0>a&&(a=Math.max(e.length+a,0));if(void 0===c)return void 0===a?e:e[a];if(null===a||void 0===e[a])if(u(c)){e=[];a=0;for(var f=c.length;ab)return a.charAt(0)===c.charAt(0)&&"/"===a.charAt(0)?"/":"";if("/"!==a.charAt(b)||"/"!==c.charAt(b))b=a.substring(0,b).lastIndexOf("/");return a.substring(0,b+1)};b.withinString=function(a,c,d){d||(d={});var l=d.start||b.findUri.start,m=d.end||b.findUri.end,e=d.trim||b.findUri.trim,g= +d.parens||b.findUri.parens,f=/[a-z0-9-]=["']?$/i;for(l.lastIndex=0;;){var h=l.exec(a);if(!h)break;var k=h.index;if(d.ignoreHtml){var p=a.slice(Math.max(k-3,0),k);if(p&&f.test(p))continue}var n=k+a.slice(k).search(m);p=a.slice(k,n);for(n=-1;;){var r=g.exec(p);if(!r)break;n=Math.max(n,r.index+r[0].length)}p=-1c))throw new TypeError('Port "'+a+'" is not a valid port');}};b.noConflict=function(a){if(a)return a={URI:this.noConflict()},k.URITemplate&&"function"===typeof k.URITemplate.noConflict&&(a.URITemplate=k.URITemplate.noConflict()),k.IPv6&&"function"===typeof k.IPv6.noConflict&&(a.IPv6=k.IPv6.noConflict()),k.SecondLevelDomains&&"function"===typeof k.SecondLevelDomains.noConflict&&(a.SecondLevelDomains=k.SecondLevelDomains.noConflict()), +a;k.URI===this&&(k.URI=w);return this};e.build=function(a){if(!0===a)this._deferred_build=!0;else if(void 0===a||this._deferred_build)this._string=b.build(this._parts),this._deferred_build=!1;return this};e.clone=function(){return new b(this)};e.valueOf=e.toString=function(){return this.build(!1)._string};e.protocol=r("protocol");e.username=r("username");e.password=r("password");e.hostname=r("hostname");e.port=r("port");e.query=C("query","?");e.fragment=C("fragment","#");e.search=function(a,c){var b= +this.query(a,c);return"string"===typeof b&&b.length?"?"+b:b};e.hash=function(a,c){var b=this.fragment(a,c);return"string"===typeof b&&b.length?"#"+b:b};e.pathname=function(a,c){if(void 0===a||!0===a){var d=this._parts.path||(this._parts.hostname?"/":"");return a?(this._parts.urn?b.decodeUrnPath:b.decodePath)(d):d}this._parts.path=this._parts.urn?a?b.recodeUrnPath(a):"":a?b.recodePath(a):"/";this.build(!c);return this};e.path=e.pathname;e.href=function(a,c){var d;if(void 0===a)return this.toString(); +this._string="";this._parts=b._parts();var l=a instanceof b,e="object"===typeof a&&(a.hostname||a.path||a.pathname);a.nodeName&&(e=b.getDomAttribute(a),a=a[e]||"",e=!1);!l&&e&&void 0!==a.pathname&&(a=a.toString());if("string"===typeof a||a instanceof String)this._parts=b.parse(String(a),this._parts);else if(l||e)for(d in l=l?a._parts:a,l)t.call(this._parts,d)&&(this._parts[d]=l[d]);else throw new TypeError("invalid input");this.build(!c);return this};e.is=function(a){var c=!1,d=!1,e=!1,m=!1,g=!1, +f=!1,k=!1,p=!this._parts.urn;this._parts.hostname&&(p=!1,d=b.ip4_expression.test(this._parts.hostname),e=b.ip6_expression.test(this._parts.hostname),c=d||e,g=(m=!c)&&h&&h.has(this._parts.hostname),f=m&&b.idn_expression.test(this._parts.hostname),k=m&&b.punycode_expression.test(this._parts.hostname));switch(a.toLowerCase()){case "relative":return p;case "absolute":return!p;case "domain":case "name":return m;case "sld":return g;case "ip":return c;case "ip4":case "ipv4":case "inet4":return d;case "ip6":case "ipv6":case "inet6":return e; +case "idn":return f;case "url":return!this._parts.urn;case "urn":return!!this._parts.urn;case "punycode":return k}return null};var G=e.protocol,H=e.port,I=e.hostname;e.protocol=function(a,c){if(a&&(a=a.replace(/:(\/\/)?$/,""),!a.match(b.protocol_expression)))throw new TypeError('Protocol "'+a+"\" contains characters other than [A-Z0-9.+-] or doesn't start with [A-Z]");return G.call(this,a,c)};e.scheme=e.protocol;e.port=function(a,c){if(this._parts.urn)return void 0===a?"":this;void 0!==a&&(0===a&& +(a=null),a&&(a+="",":"===a.charAt(0)&&(a=a.substring(1)),b.ensureValidPort(a)));return H.call(this,a,c)};e.hostname=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0!==a){var d={preventInvalidHostname:this._parts.preventInvalidHostname};if("/"!==b.parseHost(a,d))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]');a=d.hostname;this._parts.preventInvalidHostname&&b.ensureValidHostname(a,this._parts.protocol)}return I.call(this,a,c)};e.origin=function(a, +c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){var d=this.protocol();return this.authority()?(d?d+"://":"")+this.authority():""}d=b(a);this.protocol(d.protocol()).authority(d.authority()).build(!c);return this};e.host=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a)return this._parts.hostname?b.buildHost(this._parts):"";if("/"!==b.parseHost(a,this._parts))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]');this.build(!c);return this}; +e.authority=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a)return this._parts.hostname?b.buildAuthority(this._parts):"";if("/"!==b.parseAuthority(a,this._parts))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]');this.build(!c);return this};e.userinfo=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){var d=b.buildUserinfo(this._parts);return d?d.substring(0,d.length-1):d}"@"!==a[a.length-1]&&(a+="@");b.parseUserinfo(a, +this._parts);this.build(!c);return this};e.resource=function(a,c){if(void 0===a)return this.path()+this.search()+this.hash();var d=b.parse(a);this._parts.path=d.path;this._parts.query=d.query;this._parts.fragment=d.fragment;this.build(!c);return this};e.subdomain=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var d=this._parts.hostname.length-this.domain().length-1;return this._parts.hostname.substring(0,d)||""}d=this._parts.hostname.length- +this.domain().length;d=this._parts.hostname.substring(0,d);d=new RegExp("^"+q(d));a&&"."!==a.charAt(a.length-1)&&(a+=".");if(-1!==a.indexOf(":"))throw new TypeError("Domains cannot contain colons");a&&b.ensureValidHostname(a,this._parts.protocol);this._parts.hostname=this._parts.hostname.replace(d,a);this.build(!c);return this};e.domain=function(a,c){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(c=a,a=void 0);if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var d= +this._parts.hostname.match(/\./g);if(d&&2>d.length)return this._parts.hostname;d=this._parts.hostname.length-this.tld(c).length-1;d=this._parts.hostname.lastIndexOf(".",d-1)+1;return this._parts.hostname.substring(d)||""}if(!a)throw new TypeError("cannot set domain empty");if(-1!==a.indexOf(":"))throw new TypeError("Domains cannot contain colons");b.ensureValidHostname(a,this._parts.protocol);!this._parts.hostname||this.is("IP")?this._parts.hostname=a:(d=new RegExp(q(this.domain())+"$"),this._parts.hostname= +this._parts.hostname.replace(d,a));this.build(!c);return this};e.tld=function(a,c){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(c=a,a=void 0);if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var b=this._parts.hostname.lastIndexOf(".");b=this._parts.hostname.substring(b+1);return!0!==c&&h&&h.list[b.toLowerCase()]?h.get(this._parts.hostname)||b:b}if(a)if(a.match(/[^a-zA-Z0-9-]/))if(h&&h.is(a))b=new RegExp(q(this.tld())+"$"),this._parts.hostname=this._parts.hostname.replace(b, +a);else throw new TypeError('TLD "'+a+'" contains characters other than [A-Z0-9]');else{if(!this._parts.hostname||this.is("IP"))throw new ReferenceError("cannot set TLD on non-domain host");b=new RegExp(q(this.tld())+"$");this._parts.hostname=this._parts.hostname.replace(b,a)}else throw new TypeError("cannot set TLD empty");this.build(!c);return this};e.directory=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path&&!this._parts.hostname)return""; +if("/"===this._parts.path)return"/";var d=this._parts.path.length-this.filename().length-1;d=this._parts.path.substring(0,d)||(this._parts.hostname?"/":"");return a?b.decodePath(d):d}d=this._parts.path.length-this.filename().length;d=this._parts.path.substring(0,d);d=new RegExp("^"+q(d));this.is("relative")||(a||(a="/"),"/"!==a.charAt(0)&&(a="/"+a));a&&"/"!==a.charAt(a.length-1)&&(a+="/");a=b.recodePath(a);this._parts.path=this._parts.path.replace(d,a);this.build(!c);return this};e.filename=function(a, +c){if(this._parts.urn)return void 0===a?"":this;if("string"!==typeof a){if(!this._parts.path||"/"===this._parts.path)return"";var d=this._parts.path.lastIndexOf("/");d=this._parts.path.substring(d+1);return a?b.decodePathSegment(d):d}d=!1;"/"===a.charAt(0)&&(a=a.substring(1));a.match(/\.?\//)&&(d=!0);var e=new RegExp(q(this.filename())+"$");a=b.recodePath(a);this._parts.path=this._parts.path.replace(e,a);d?this.normalizePath(c):this.build(!c);return this};e.suffix=function(a,c){if(this._parts.urn)return void 0=== +a?"":this;if(void 0===a||!0===a){if(!this._parts.path||"/"===this._parts.path)return"";var d=this.filename(),e=d.lastIndexOf(".");if(-1===e)return"";d=d.substring(e+1);d=/^[a-z0-9%]+$/i.test(d)?d:"";return a?b.decodePathSegment(d):d}"."===a.charAt(0)&&(a=a.substring(1));if(d=this.suffix())e=a?new RegExp(q(d)+"$"):new RegExp(q("."+d)+"$");else{if(!a)return this;this._parts.path+="."+b.recodePath(a)}e&&(a=b.recodePath(a),this._parts.path=this._parts.path.replace(e,a));this.build(!c);return this};e.segment= +function(a,c,b){var d=this._parts.urn?":":"/",e=this.path(),g="/"===e.substring(0,1);e=e.split(d);void 0!==a&&"number"!==typeof a&&(b=c,c=a,a=void 0);if(void 0!==a&&"number"!==typeof a)throw Error('Bad segment "'+a+'", must be 0-based integer');g&&e.shift();0>a&&(a=Math.max(e.length+a,0));if(void 0===c)return void 0===a?e:e[a];if(null===a||void 0===e[a])if(u(c)){e=[];a=0;for(var f=c.length;a{}"`^| \\]/;h.expand=function(b,f,k){var g=u[b.operator],p=g.named?"Named":"Unnamed";b=b.variables;var m=[],r,q;for(q=0;r=b[q];q++){var w=f.get(r.name);if(0===w.type&&k&&k.strict)throw Error('Missing expansion value for variable "'+ -r.name+'"');if(w.val.length){if(1{}"`^| \\]/;h.expand=function(b,f,k){var g=u[b.operator],p=g.named?"Named":"Unnamed";b=b.variables;var n=[],r,q;for(q=0;r=b[q];q++){var w=f.get(r.name);if(0===w.type&&k&&k.strict)throw Error('Missing expansion value for variable "'+ +r.name+'"');if(w.val.length){if(1 Date: Sat, 10 Feb 2018 11:45:58 -0300 Subject: [PATCH 33/44] fix(core): properly parse query property (#367) closes #366 --- src/URI.js | 4 ++++ test/test.js | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/URI.js b/src/URI.js index 1d7957a0..d2cf26d6 100644 --- a/src/URI.js +++ b/src/URI.js @@ -1241,10 +1241,14 @@ } else if (_URI || _object) { var src = _URI ? href._parts : href; for (key in src) { + if (key === 'query') { continue; } if (hasOwn.call(this._parts, key)) { this._parts[key] = src[key]; } } + if (src.query) { + this.query(src.query, false); + } } else { throw new TypeError('invalid input'); } diff --git a/test/test.js b/test/test.js index fe62c01c..c29c2ad1 100644 --- a/test/test.js +++ b/test/test.js @@ -34,6 +34,49 @@ ok(u instanceof URI, 'instanceof URI'); ok(u._parts.hostname !== undefined, 'host undefined'); }); + + test('new URI(object)', function() { + var u = new URI({ + protocol: 'http', + hostname: 'example.org', + query: { + foo: 'bar', + bar: 'foo', + }, + }); + ok(u instanceof URI, 'instanceof URI'); + ok(typeof u.query() === 'string', 'query is string'); + equal(u.query(), 'foo=bar&bar=foo', 'query has right value'); + equal(u.search(), '?foo=bar&bar=foo', 'search has right value'); + deepEqual(u.query(true), { foo: 'bar', bar: 'foo' }, 'query(true) value'); + deepEqual(u.search(true), { foo: 'bar', bar: 'foo' }, 'search(true) value'); + }); + test('new URI(object)', function() { + var u = new URI({ + protocol: 'http', + hostname: 'example.org', + query: 'foo=bar&bar=foo', + }); + ok(u instanceof URI, 'instanceof URI'); + ok(typeof u.query() === 'string', 'query is string'); + equal(u.query(), 'foo=bar&bar=foo', 'query has right value'); + equal(u.search(), '?foo=bar&bar=foo', 'search has right value'); + deepEqual(u.query(true), { foo: 'bar', bar: 'foo' }, 'query(true) value'); + deepEqual(u.search(true), { foo: 'bar', bar: 'foo' }, 'search(true) value'); + }); + test('new URI(object)', function() { + var u = new URI({ + protocol: 'http', + hostname: 'example.org', + query: '?foo=bar&bar=foo', + }); + ok(u instanceof URI, 'instanceof URI'); + ok(typeof u.query() === 'string', 'query is string'); + equal(u.query(), 'foo=bar&bar=foo', 'query has right value'); + equal(u.search(), '?foo=bar&bar=foo', 'search has right value'); + deepEqual(u.query(true), { foo: 'bar', bar: 'foo' }, 'query(true) value'); + deepEqual(u.search(true), { foo: 'bar', bar: 'foo' }, 'search(true) value'); + }); test('new URI(Location)', function () { var u = new URI(location); equal(u.href(), String(location.href), 'location object'); From fa46615b9934217a971edd482b59b9f88303db00 Mon Sep 17 00:00:00 2001 From: Rodney Rehm Date: Sat, 10 Feb 2018 16:33:18 +0100 Subject: [PATCH 34/44] chore(build): bumping to version 1.19.1 --- CHANGELOG.md | 4 ++++ bower.json | 2 +- build.js | 18 ++++++++-------- package.json | 2 +- src/IPv6.js | 2 +- src/SecondLevelDomains.js | 2 +- src/URI.js | 4 ++-- src/URI.min.js | 44 +++++++++++++++++++-------------------- src/URITemplate.js | 2 +- src/jquery.URI.js | 28 ++++++++++++------------- src/jquery.URI.min.js | 2 +- 11 files changed, 57 insertions(+), 53 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a90344a..e3641caa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ The release notes tracked in this document are also made available on the [releases page](https://github.com/medialize/URI.js/releases) +### 1.19.1 (February 10th 2018) ### + +* fixing [`.href()`](http://medialize.github.io/URI.js/docs.html#href) to parse `query` property - [Issue #366](https://github.com/medialize/URI.js/issues/366), [PR #367](https://github.com/medialize/URI.js/issues/367) + ### 1.19.0 (October 1st 2017) ### * adding `.setFragment()` to [query fragment plugin](http://medialize.github.io/URI.js/docs.html#fragment-abuse-query) - [Issue #338](https://github.com/medialize/URI.js/issues/338), [PR #356](https://github.com/medialize/URI.js/issues/356) diff --git a/bower.json b/bower.json index 5a4b37dd..a043b31a 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "urijs", - "version": "1.19.0", + "version": "1.19.1", "main": "src/URI.js", "ignore": [ ".*", diff --git a/build.js b/build.js index c17a8d31..df195827 100644 --- a/build.js +++ b/build.js @@ -1,17 +1,17 @@ (function($, undefined){ window.URL = window.webkitURL || window.URL; window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder; - + function build(files) { var $out = $('#output'), $progress = $('#prog'), sources = [], connections = [], source; - + $out.parent().hide(); $progress.show().prop('value', 1).text('Loading Files'); - + for (var i = 0, length = files.length; i < length; i++) { sources.push(""); (function(i, file){ @@ -20,7 +20,7 @@ function build(files) { }, "text")); })(i, files[i]); } - + $.when.apply($, connections).done(function() { $progress.prop('value', 2).text('Compiling Scripts'); $.post('https://closure-compiler.appspot.com/compile', { @@ -29,13 +29,13 @@ function build(files) { output_format: "text", output_info: "compiled_code" }, function(data) { - var code = "/*! URI.js v1.19.0 http://medialize.github.io/URI.js/ */\n/* build contains: " + files.join(', ') + " */\n" + data; + var code = "/*! URI.js v1.19.1 http://medialize.github.io/URI.js/ */\n/* build contains: " + files.join(', ') + " */\n" + data; $progress.hide(); $out.val(code).parent().show(); $out.prev().find('a').remove(); $out.prev().prepend(download(code)); - }).error(function() { - alert("Your browser is incapable of cross-domain communication.\nPlease see instructions for manual build below."); + }).error(function() { + alert("Your browser is incapable of cross-domain communication.\nPlease see instructions for manual build below."); }); }); }; @@ -48,7 +48,7 @@ function download(code) { a.href = window.URL.createObjectURL(blob); a.textContent = 'Download'; a.dataset.downloadurl = ['text/javascript', a.download, a.href].join(':'); - + return a; }; @@ -70,7 +70,7 @@ $(function(){ var val = $(this).val(); val.length && files.push(val); }); - + build(files); }); }); diff --git a/package.json b/package.json index 2998baee..fdd0829f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "urijs", - "version": "1.19.0", + "version": "1.19.1", "title": "URI.js - Mutating URLs", "author": { "name": "Rodney Rehm", diff --git a/src/IPv6.js b/src/IPv6.js index 5f389450..9aa9e9c5 100644 --- a/src/IPv6.js +++ b/src/IPv6.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * IPv6 Support * - * Version: 1.19.0 + * Version: 1.19.1 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/SecondLevelDomains.js b/src/SecondLevelDomains.js index e926a05b..2396a15b 100644 --- a/src/SecondLevelDomains.js +++ b/src/SecondLevelDomains.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * Second Level Domain (SLD) Support * - * Version: 1.19.0 + * Version: 1.19.1 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/URI.js b/src/URI.js index d2cf26d6..cb52699e 100644 --- a/src/URI.js +++ b/src/URI.js @@ -1,7 +1,7 @@ /*! * URI.js - Mutating URLs * - * Version: 1.19.0 + * Version: 1.19.1 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ @@ -81,7 +81,7 @@ return /^[0-9]+$/.test(value); } - URI.version = '1.19.0'; + URI.version = '1.19.1'; var p = URI.prototype; var hasOwn = Object.prototype.hasOwnProperty; diff --git a/src/URI.min.js b/src/URI.min.js index 5386babf..75c8a4c7 100644 --- a/src/URI.min.js +++ b/src/URI.min.js @@ -1,4 +1,4 @@ -/*! URI.js v1.19.0 http://medialize.github.io/URI.js/ */ +/*! URI.js v1.19.1 http://medialize.github.io/URI.js/ */ /* build contains: IPv6.js, punycode.js, SecondLevelDomains.js, URI.js, URITemplate.js */ (function(f,n){"object"===typeof module&&module.exports?module.exports=n():"function"===typeof define&&define.amd?define(n):f.IPv6=n(f)})(this,function(f){var n=f&&f.IPv6;return{best:function(h){h=h.toLowerCase().split(":");var k=h.length,b=8;""===h[0]&&""===h[1]&&""===h[2]?(h.shift(),h.shift()):""===h[0]&&""===h[1]?h.shift():""===h[k-1]&&""===h[k-2]&&h.pop();k=h.length;-1!==h[k-1].indexOf(".")&&(b=7);var q;for(q=0;qf;f++)if("0"===k[0]&&1f&&(k=g,f=n)):"0"===h[q]&&(p=!0,g=q,n=1);n>f&&(k=g,f=n);1=k||k>=b-1)return null;var n=h.list[f.slice(b+1)];return!n||0>n.indexOf(" " (function(f,n){"object"===typeof module&&module.exports?module.exports=n(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"===typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],n):f.URI=n(f.punycode,f.IPv6,f.SecondLevelDomains,f)})(this,function(f,n,h,k){function b(a,c){var d=1<=arguments.length,l=2<=arguments.length;if(!(this instanceof b))return d?l?new b(a,c):new b(a):new b;if(void 0===a){if(d)throw new TypeError("undefined is not a valid argument for URI"); a="undefined"!==typeof location?location.href+"":""}if(null===a&&d)throw new TypeError("null is not a valid argument for URI");this.href(a);return void 0!==c?this.absoluteTo(c):this}function q(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function z(a){return void 0===a?"Undefined":String(Object.prototype.toString.call(a)).slice(8,-1)}function u(a){return"Array"===z(a)}function g(a,c){var d={},b;if("RegExp"===z(c))d=null;else if(u(c)){var m=0;for(b=c.length;m]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u2018\u2019]))/ig;b.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u201e\u2018\u2019]+$/,parens:/(\([^\)]*\)|\[[^\]]*\]|\{[^}]*\}|<[^>]*>)/g};b.defaultPorts={http:"80",https:"443",ftp:"21", @@ -51,26 +51,26 @@ l.lastIndex=k+h.length))}l.lastIndex=0;return a};b.ensureValidHostname=function( }};b.ensureValidPort=function(a){if(a){var c=Number(a);if(!(/^[0-9]+$/.test(c)&&0c))throw new TypeError('Port "'+a+'" is not a valid port');}};b.noConflict=function(a){if(a)return a={URI:this.noConflict()},k.URITemplate&&"function"===typeof k.URITemplate.noConflict&&(a.URITemplate=k.URITemplate.noConflict()),k.IPv6&&"function"===typeof k.IPv6.noConflict&&(a.IPv6=k.IPv6.noConflict()),k.SecondLevelDomains&&"function"===typeof k.SecondLevelDomains.noConflict&&(a.SecondLevelDomains=k.SecondLevelDomains.noConflict()), a;k.URI===this&&(k.URI=w);return this};e.build=function(a){if(!0===a)this._deferred_build=!0;else if(void 0===a||this._deferred_build)this._string=b.build(this._parts),this._deferred_build=!1;return this};e.clone=function(){return new b(this)};e.valueOf=e.toString=function(){return this.build(!1)._string};e.protocol=r("protocol");e.username=r("username");e.password=r("password");e.hostname=r("hostname");e.port=r("port");e.query=C("query","?");e.fragment=C("fragment","#");e.search=function(a,c){var b= this.query(a,c);return"string"===typeof b&&b.length?"?"+b:b};e.hash=function(a,c){var b=this.fragment(a,c);return"string"===typeof b&&b.length?"#"+b:b};e.pathname=function(a,c){if(void 0===a||!0===a){var d=this._parts.path||(this._parts.hostname?"/":"");return a?(this._parts.urn?b.decodeUrnPath:b.decodePath)(d):d}this._parts.path=this._parts.urn?a?b.recodeUrnPath(a):"":a?b.recodePath(a):"/";this.build(!c);return this};e.path=e.pathname;e.href=function(a,c){var d;if(void 0===a)return this.toString(); -this._string="";this._parts=b._parts();var l=a instanceof b,e="object"===typeof a&&(a.hostname||a.path||a.pathname);a.nodeName&&(e=b.getDomAttribute(a),a=a[e]||"",e=!1);!l&&e&&void 0!==a.pathname&&(a=a.toString());if("string"===typeof a||a instanceof String)this._parts=b.parse(String(a),this._parts);else if(l||e)for(d in l=l?a._parts:a,l)t.call(this._parts,d)&&(this._parts[d]=l[d]);else throw new TypeError("invalid input");this.build(!c);return this};e.is=function(a){var c=!1,d=!1,e=!1,m=!1,g=!1, -f=!1,k=!1,p=!this._parts.urn;this._parts.hostname&&(p=!1,d=b.ip4_expression.test(this._parts.hostname),e=b.ip6_expression.test(this._parts.hostname),c=d||e,g=(m=!c)&&h&&h.has(this._parts.hostname),f=m&&b.idn_expression.test(this._parts.hostname),k=m&&b.punycode_expression.test(this._parts.hostname));switch(a.toLowerCase()){case "relative":return p;case "absolute":return!p;case "domain":case "name":return m;case "sld":return g;case "ip":return c;case "ip4":case "ipv4":case "inet4":return d;case "ip6":case "ipv6":case "inet6":return e; -case "idn":return f;case "url":return!this._parts.urn;case "urn":return!!this._parts.urn;case "punycode":return k}return null};var G=e.protocol,H=e.port,I=e.hostname;e.protocol=function(a,c){if(a&&(a=a.replace(/:(\/\/)?$/,""),!a.match(b.protocol_expression)))throw new TypeError('Protocol "'+a+"\" contains characters other than [A-Z0-9.+-] or doesn't start with [A-Z]");return G.call(this,a,c)};e.scheme=e.protocol;e.port=function(a,c){if(this._parts.urn)return void 0===a?"":this;void 0!==a&&(0===a&& -(a=null),a&&(a+="",":"===a.charAt(0)&&(a=a.substring(1)),b.ensureValidPort(a)));return H.call(this,a,c)};e.hostname=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0!==a){var d={preventInvalidHostname:this._parts.preventInvalidHostname};if("/"!==b.parseHost(a,d))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]');a=d.hostname;this._parts.preventInvalidHostname&&b.ensureValidHostname(a,this._parts.protocol)}return I.call(this,a,c)};e.origin=function(a, -c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){var d=this.protocol();return this.authority()?(d?d+"://":"")+this.authority():""}d=b(a);this.protocol(d.protocol()).authority(d.authority()).build(!c);return this};e.host=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a)return this._parts.hostname?b.buildHost(this._parts):"";if("/"!==b.parseHost(a,this._parts))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]');this.build(!c);return this}; -e.authority=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a)return this._parts.hostname?b.buildAuthority(this._parts):"";if("/"!==b.parseAuthority(a,this._parts))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]');this.build(!c);return this};e.userinfo=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){var d=b.buildUserinfo(this._parts);return d?d.substring(0,d.length-1):d}"@"!==a[a.length-1]&&(a+="@");b.parseUserinfo(a, -this._parts);this.build(!c);return this};e.resource=function(a,c){if(void 0===a)return this.path()+this.search()+this.hash();var d=b.parse(a);this._parts.path=d.path;this._parts.query=d.query;this._parts.fragment=d.fragment;this.build(!c);return this};e.subdomain=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var d=this._parts.hostname.length-this.domain().length-1;return this._parts.hostname.substring(0,d)||""}d=this._parts.hostname.length- -this.domain().length;d=this._parts.hostname.substring(0,d);d=new RegExp("^"+q(d));a&&"."!==a.charAt(a.length-1)&&(a+=".");if(-1!==a.indexOf(":"))throw new TypeError("Domains cannot contain colons");a&&b.ensureValidHostname(a,this._parts.protocol);this._parts.hostname=this._parts.hostname.replace(d,a);this.build(!c);return this};e.domain=function(a,c){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(c=a,a=void 0);if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var d= -this._parts.hostname.match(/\./g);if(d&&2>d.length)return this._parts.hostname;d=this._parts.hostname.length-this.tld(c).length-1;d=this._parts.hostname.lastIndexOf(".",d-1)+1;return this._parts.hostname.substring(d)||""}if(!a)throw new TypeError("cannot set domain empty");if(-1!==a.indexOf(":"))throw new TypeError("Domains cannot contain colons");b.ensureValidHostname(a,this._parts.protocol);!this._parts.hostname||this.is("IP")?this._parts.hostname=a:(d=new RegExp(q(this.domain())+"$"),this._parts.hostname= -this._parts.hostname.replace(d,a));this.build(!c);return this};e.tld=function(a,c){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(c=a,a=void 0);if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var b=this._parts.hostname.lastIndexOf(".");b=this._parts.hostname.substring(b+1);return!0!==c&&h&&h.list[b.toLowerCase()]?h.get(this._parts.hostname)||b:b}if(a)if(a.match(/[^a-zA-Z0-9-]/))if(h&&h.is(a))b=new RegExp(q(this.tld())+"$"),this._parts.hostname=this._parts.hostname.replace(b, -a);else throw new TypeError('TLD "'+a+'" contains characters other than [A-Z0-9]');else{if(!this._parts.hostname||this.is("IP"))throw new ReferenceError("cannot set TLD on non-domain host");b=new RegExp(q(this.tld())+"$");this._parts.hostname=this._parts.hostname.replace(b,a)}else throw new TypeError("cannot set TLD empty");this.build(!c);return this};e.directory=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path&&!this._parts.hostname)return""; -if("/"===this._parts.path)return"/";var d=this._parts.path.length-this.filename().length-1;d=this._parts.path.substring(0,d)||(this._parts.hostname?"/":"");return a?b.decodePath(d):d}d=this._parts.path.length-this.filename().length;d=this._parts.path.substring(0,d);d=new RegExp("^"+q(d));this.is("relative")||(a||(a="/"),"/"!==a.charAt(0)&&(a="/"+a));a&&"/"!==a.charAt(a.length-1)&&(a+="/");a=b.recodePath(a);this._parts.path=this._parts.path.replace(d,a);this.build(!c);return this};e.filename=function(a, -c){if(this._parts.urn)return void 0===a?"":this;if("string"!==typeof a){if(!this._parts.path||"/"===this._parts.path)return"";var d=this._parts.path.lastIndexOf("/");d=this._parts.path.substring(d+1);return a?b.decodePathSegment(d):d}d=!1;"/"===a.charAt(0)&&(a=a.substring(1));a.match(/\.?\//)&&(d=!0);var e=new RegExp(q(this.filename())+"$");a=b.recodePath(a);this._parts.path=this._parts.path.replace(e,a);d?this.normalizePath(c):this.build(!c);return this};e.suffix=function(a,c){if(this._parts.urn)return void 0=== -a?"":this;if(void 0===a||!0===a){if(!this._parts.path||"/"===this._parts.path)return"";var d=this.filename(),e=d.lastIndexOf(".");if(-1===e)return"";d=d.substring(e+1);d=/^[a-z0-9%]+$/i.test(d)?d:"";return a?b.decodePathSegment(d):d}"."===a.charAt(0)&&(a=a.substring(1));if(d=this.suffix())e=a?new RegExp(q(d)+"$"):new RegExp(q("."+d)+"$");else{if(!a)return this;this._parts.path+="."+b.recodePath(a)}e&&(a=b.recodePath(a),this._parts.path=this._parts.path.replace(e,a));this.build(!c);return this};e.segment= -function(a,c,b){var d=this._parts.urn?":":"/",e=this.path(),g="/"===e.substring(0,1);e=e.split(d);void 0!==a&&"number"!==typeof a&&(b=c,c=a,a=void 0);if(void 0!==a&&"number"!==typeof a)throw Error('Bad segment "'+a+'", must be 0-based integer');g&&e.shift();0>a&&(a=Math.max(e.length+a,0));if(void 0===c)return void 0===a?e:e[a];if(null===a||void 0===e[a])if(u(c)){e=[];a=0;for(var f=c.length;ad.length)return this._parts.hostname;d=this._parts.hostname.length-this.tld(c).length-1;d=this._parts.hostname.lastIndexOf(".",d-1)+1;return this._parts.hostname.substring(d)||""}if(!a)throw new TypeError("cannot set domain empty");if(-1!==a.indexOf(":"))throw new TypeError("Domains cannot contain colons");b.ensureValidHostname(a,this._parts.protocol);!this._parts.hostname||this.is("IP")?this._parts.hostname=a:(d=new RegExp(q(this.domain())+ +"$"),this._parts.hostname=this._parts.hostname.replace(d,a));this.build(!c);return this};e.tld=function(a,c){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(c=a,a=void 0);if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var b=this._parts.hostname.lastIndexOf(".");b=this._parts.hostname.substring(b+1);return!0!==c&&h&&h.list[b.toLowerCase()]?h.get(this._parts.hostname)||b:b}if(a)if(a.match(/[^a-zA-Z0-9-]/))if(h&&h.is(a))b=new RegExp(q(this.tld())+"$"),this._parts.hostname= +this._parts.hostname.replace(b,a);else throw new TypeError('TLD "'+a+'" contains characters other than [A-Z0-9]');else{if(!this._parts.hostname||this.is("IP"))throw new ReferenceError("cannot set TLD on non-domain host");b=new RegExp(q(this.tld())+"$");this._parts.hostname=this._parts.hostname.replace(b,a)}else throw new TypeError("cannot set TLD empty");this.build(!c);return this};e.directory=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path&& +!this._parts.hostname)return"";if("/"===this._parts.path)return"/";var d=this._parts.path.length-this.filename().length-1;d=this._parts.path.substring(0,d)||(this._parts.hostname?"/":"");return a?b.decodePath(d):d}d=this._parts.path.length-this.filename().length;d=this._parts.path.substring(0,d);d=new RegExp("^"+q(d));this.is("relative")||(a||(a="/"),"/"!==a.charAt(0)&&(a="/"+a));a&&"/"!==a.charAt(a.length-1)&&(a+="/");a=b.recodePath(a);this._parts.path=this._parts.path.replace(d,a);this.build(!c); +return this};e.filename=function(a,c){if(this._parts.urn)return void 0===a?"":this;if("string"!==typeof a){if(!this._parts.path||"/"===this._parts.path)return"";var d=this._parts.path.lastIndexOf("/");d=this._parts.path.substring(d+1);return a?b.decodePathSegment(d):d}d=!1;"/"===a.charAt(0)&&(a=a.substring(1));a.match(/\.?\//)&&(d=!0);var e=new RegExp(q(this.filename())+"$");a=b.recodePath(a);this._parts.path=this._parts.path.replace(e,a);d?this.normalizePath(c):this.build(!c);return this};e.suffix= +function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path||"/"===this._parts.path)return"";var d=this.filename(),e=d.lastIndexOf(".");if(-1===e)return"";d=d.substring(e+1);d=/^[a-z0-9%]+$/i.test(d)?d:"";return a?b.decodePathSegment(d):d}"."===a.charAt(0)&&(a=a.substring(1));if(d=this.suffix())e=a?new RegExp(q(d)+"$"):new RegExp(q("."+d)+"$");else{if(!a)return this;this._parts.path+="."+b.recodePath(a)}e&&(a=b.recodePath(a),this._parts.path=this._parts.path.replace(e, +a));this.build(!c);return this};e.segment=function(a,c,b){var d=this._parts.urn?":":"/",e=this.path(),g="/"===e.substring(0,1);e=e.split(d);void 0!==a&&"number"!==typeof a&&(b=c,c=a,a=void 0);if(void 0!==a&&"number"!==typeof a)throw Error('Bad segment "'+a+'", must be 0-based integer');g&&e.shift();0>a&&(a=Math.max(e.length+a,0));if(void 0===c)return void 0===a?e:e[a];if(null===a||void 0===e[a])if(u(c)){e=[];a=0;for(var f=c.length;a that is not an image return undefined; } - + // NOTE: as we use a static mapping from element to attribute, // the HTML5 attribute issue should not come up again // https://github.com/medialize/URI.js/issues/69 @@ -120,17 +120,17 @@ var $this = this.first(); var elem = $this.get(0); var property = getUriProperty(elem); - + if (!property) { throw new Error('Element "' + elem.nodeName + '" does not have either property: href, src, action, cite'); } - + if (uri !== undefined) { var old = $this.data('uri'); if (old) { return old.href(uri); } - + if (!(uri instanceof URI)) { uri = URI(uri || ''); } @@ -142,7 +142,7 @@ uri = URI($this.attr(property) || ''); } } - + uri._dom_element = elem; uri._dom_attribute = property; uri.normalize(); @@ -164,7 +164,7 @@ this._string = URI.build(this._parts); this._deferred_build = false; } - + return this; }; @@ -173,12 +173,12 @@ var pseudoArgs = /^([a-zA-Z]+)\s*([\^\$*]?=|:)\s*(['"]?)(.+)\3|^\s*([a-zA-Z0-9]+)\s*$/; function uriPseudo (elem, text) { var match, property, uri; - + // skip anything without src|href|action and bad :uri() syntax if (!getUriProperty(elem) || !text) { return false; } - + match = text.match(pseudoArgs); if (!match || (!match[5] && match[2] !== ':' && !compare[match[2]])) { @@ -188,7 +188,7 @@ } uri = $(elem).uri(); - + if (match[5]) { return uri.is(match[5]); } else if (match[2] === ':') { @@ -197,7 +197,7 @@ // filers seem to fail silently return false; } - + return compare[property](uri, match[4]); } else { property = match[1].toLowerCase(); @@ -205,7 +205,7 @@ // filers seem to fail silently return false; } - + return compare[match[2]](uri[property](), match[4], property); } diff --git a/src/jquery.URI.min.js b/src/jquery.URI.min.js index ee4fc37f..dc19566d 100644 --- a/src/jquery.URI.min.js +++ b/src/jquery.URI.min.js @@ -1,4 +1,4 @@ -/*! URI.js v1.19.0 http://medialize.github.io/URI.js/ */ +/*! URI.js v1.19.1 http://medialize.github.io/URI.js/ */ /* build contains: jquery.URI.js */ (function(d,e){"object"===typeof module&&module.exports?module.exports=e(require("jquery"),require("./URI")):"function"===typeof define&&define.amd?define(["jquery","./URI"],e):e(d.jQuery,d.URI)})(this,function(d,e){function h(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function k(a){var b=a.nodeName.toLowerCase();if("input"!==b||"image"===a.type)return e.domAttributes[b]}function n(a){return{get:function(b){return d(b).uri()[a]()},set:function(b,c){d(b).uri()[a](c);return c}}}function l(a, b){if(!k(a)||!b)return!1;var c=b.match(p);if(!c||!c[5]&&":"!==c[2]&&!g[c[2]])return!1;var e=d(a).uri();if(c[5])return e.is(c[5]);if(":"===c[2]){var f=c[1].toLowerCase()+":";return g[f]?g[f](e,c[4]):!1}f=c[1].toLowerCase();return m[f]?g[c[2]](e[f](),c[4],f):!1}var m={},g={"=":function(a,b){return a===b},"^=":function(a,b){return!!(a+"").match(new RegExp("^"+h(b),"i"))},"$=":function(a,b){return!!(a+"").match(new RegExp(h(b)+"$","i"))},"*=":function(a,b,c){"directory"===c&&(a+="/");return!!(a+"").match(new RegExp(h(b), From 7168049bd2b9b0000ea1ea46108c46e22ef57a37 Mon Sep 17 00:00:00 2001 From: Aleksey Leshko Date: Sun, 20 Oct 2019 17:19:27 +0300 Subject: [PATCH 35/44] fix(buildQuery): support params without key closes #243 #383 --- src/URI.js | 2 +- test/test.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/URI.js b/src/URI.js index cb52699e..8b0c24d6 100644 --- a/src/URI.js +++ b/src/URI.js @@ -744,7 +744,7 @@ var t = ''; var unique, key, i, length; for (key in data) { - if (hasOwn.call(data, key) && key) { + if (hasOwn.call(data, key)) { if (isArray(data[key])) { unique = {}; for (i = 0, length = data[key].length; i < length; i++) { diff --git a/test/test.js b/test/test.js index c29c2ad1..716ec761 100644 --- a/test/test.js +++ b/test/test.js @@ -1321,6 +1321,9 @@ u.query('?&foo=bar&foo=bar').normalizeQuery(); equal(u.query(), 'foo=bar', 'duplicate key=value resolution'); + + u.query('?=bar').normalizeQuery(); + equal(u.query(), '=bar', 'query without key'); }); test('normalizeFragment', function() { var u = new URI('http://example.org/foobar.html#'); @@ -1330,6 +1333,9 @@ test('readable', function() { var u = new URI('http://foo:bar@www.xn--exmple-cua.org/hello%20world/ä.html?foo%5B%5D=b+är#fragment'); equal(u.readable(), 'http://www.exämple.org/hello world/ä.html?foo[]=b är#fragment', 'readable URL'); + + var u = new URI('http://example.org/?=5640'); + equal(u.readable(), 'http://example.org/?=5640', 'readable URL: query without key'); }); module('resolving URLs'); From 4ced30a1c5ad278eae70bb06dee8d7886e68052b Mon Sep 17 00:00:00 2001 From: Rodney Rehm Date: Sun, 20 Oct 2019 16:35:25 +0200 Subject: [PATCH 36/44] fix(build): handle relative paths with missing authority closes #387 --- src/URI.js | 4 +++- test/test.js | 10 ++++++++++ test/urls.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/URI.js b/src/URI.js index 8b0c24d6..bd23fc66 100644 --- a/src/URI.js +++ b/src/URI.js @@ -669,6 +669,7 @@ URI.build = function(parts) { var t = ''; + var requireAbsolutePath = false if (parts.protocol) { t += parts.protocol + ':'; @@ -676,12 +677,13 @@ if (!parts.urn && (t || parts.hostname)) { t += '//'; + requireAbsolutePath = true } t += (URI.buildAuthority(parts) || ''); if (typeof parts.path === 'string') { - if (parts.path.charAt(0) !== '/' && typeof parts.hostname === 'string') { + if (parts.path.charAt(0) !== '/' && requireAbsolutePath) { t += '/'; } diff --git a/test/test.js b/test/test.js index 716ec761..672b3f93 100644 --- a/test/test.js +++ b/test/test.js @@ -234,6 +234,16 @@ })(t); } + module('serializing'); + test('scheme and relative path', function() { + var u = new URI('') + .protocol('food') + .path('test/file.csv') + .toString() + + equal(u.toString(), 'food:///test/file.csv', 'relative-path with scheme but no authority'); + }); + module('mutating basics'); test('protocol', function() { var u = new URI('http://example.org/foo.html'); diff --git a/test/urls.js b/test/urls.js index 06e4ae54..61d36771 100644 --- a/test/urls.js +++ b/test/urls.js @@ -629,6 +629,54 @@ var urls = [{ idn: false, punycode: false } + }, { + name: 'missing authority', + url: 'food:///test/file.csv', + parts: { + protocol: 'food', + username: null, + password: null, + hostname: null, + port: null, + path: '/test/file.csv', + query: null, + fragment: null + }, + accessors: { + protocol: 'food', + username: '', + password: '', + port: '', + path: '/test/file.csv', + query: '', + fragment: '', + resource: '/test/file.csv', + authority: '', + origin: '', + userinfo: '', + subdomain: '', + domain: '', + tld: '', + directory: '/test', + filename: 'file.csv', + suffix: 'csv', + hash: '', + search: '', + host: '', + hostname: '' + }, + is: { + urn: false, + url: true, + relative: true, + name: false, + sld: false, + ip: false, + ip4: false, + ip6: false, + idn: false, + punycode: false + } }, { name: 'IPv4', url: 'http://user:pass@123.123.123.123:123/some/directory/file.html?query=string#fragment', From 433f0e51e4028130a8685dfe49a185e982bc1f47 Mon Sep 17 00:00:00 2001 From: Mistralys Date: Sun, 20 Oct 2019 16:38:30 +0200 Subject: [PATCH 37/44] chore(package): support Composer by adding composer.json closes #386 --- composer.json | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 composer.json diff --git a/composer.json b/composer.json new file mode 100644 index 00000000..71a29072 --- /dev/null +++ b/composer.json @@ -0,0 +1,6 @@ +{ + "name": "medialize/uri.js", + "description": "URLs in JavaScript", + "type": "library", + "license": "MIT" +} From e780eebc0ddaea04a6928c0f7d54b061e541e05c Mon Sep 17 00:00:00 2001 From: Rodney Rehm Date: Sun, 20 Oct 2019 16:51:55 +0200 Subject: [PATCH 38/44] chore: inform people of modern APIs --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 06dbbffc..ecee39be 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,10 @@ --- +> **IMPORTANT:** You **may not need URI.js** anymore! Modern browsers provide the [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL) and [URLSearchParams](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) interfaces. + +--- + > **NOTE:** The npm package name changed to `urijs` --- @@ -114,7 +118,7 @@ URI("/foo/bar/baz.html") ### RequireJS ### -Clone the URI.js repository or use a package manager to get URI.js into your project. +Clone the URI.js repository or use a package manager to get URI.js into your project. ```javascript require.config({ From 594ffc1d1ba995d8e90814d6de18e1330d419be1 Mon Sep 17 00:00:00 2001 From: Rodney Rehm Date: Sun, 20 Oct 2019 16:52:23 +0200 Subject: [PATCH 39/44] chore(build): bumping to version 1.19.2 --- CHANGELOG.md | 6 ++++ bower.json | 2 +- build.js | 2 +- package.json | 2 +- src/IPv6.js | 2 +- src/SecondLevelDomains.js | 2 +- src/URI.js | 4 +-- src/URI.min.js | 70 +++++++++++++++++++-------------------- src/URITemplate.js | 2 +- src/jquery.URI.js | 2 +- src/jquery.URI.min.js | 2 +- 11 files changed, 51 insertions(+), 45 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3641caa..c32e2be4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ The release notes tracked in this document are also made available on the [releases page](https://github.com/medialize/URI.js/releases) +### 1.19.2 (October 20th 2019) ### + +* fixing [`URI.build()`](http://medialize.github.io/URI.js/docs.html#static-build) to properly handle relative paths when a scheme is given - [Issue #387](https://github.com/medialize/URI.js/issues/387) +* fixing [`URI.buildQuery()`](http://medialize.github.io/URI.js/docs.html#static-buildQuery) to properly handle empty param name - [Issue #243](https://github.com/medialize/URI.js/issues/243), [PR #383](https://github.com/medialize/URI.js/issues/383) +* support Composer [PR #386](https://github.com/medialize/URI.js/issues/386) + ### 1.19.1 (February 10th 2018) ### * fixing [`.href()`](http://medialize.github.io/URI.js/docs.html#href) to parse `query` property - [Issue #366](https://github.com/medialize/URI.js/issues/366), [PR #367](https://github.com/medialize/URI.js/issues/367) diff --git a/bower.json b/bower.json index a043b31a..62c19c08 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "urijs", - "version": "1.19.1", + "version": "1.19.2", "main": "src/URI.js", "ignore": [ ".*", diff --git a/build.js b/build.js index df195827..0a0a1fb7 100644 --- a/build.js +++ b/build.js @@ -29,7 +29,7 @@ function build(files) { output_format: "text", output_info: "compiled_code" }, function(data) { - var code = "/*! URI.js v1.19.1 http://medialize.github.io/URI.js/ */\n/* build contains: " + files.join(', ') + " */\n" + data; + var code = "/*! URI.js v1.19.2 http://medialize.github.io/URI.js/ */\n/* build contains: " + files.join(', ') + " */\n" + data; $progress.hide(); $out.val(code).parent().show(); $out.prev().find('a').remove(); diff --git a/package.json b/package.json index fdd0829f..06050f5e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "urijs", - "version": "1.19.1", + "version": "1.19.2", "title": "URI.js - Mutating URLs", "author": { "name": "Rodney Rehm", diff --git a/src/IPv6.js b/src/IPv6.js index 9aa9e9c5..31eeffb2 100644 --- a/src/IPv6.js +++ b/src/IPv6.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * IPv6 Support * - * Version: 1.19.1 + * Version: 1.19.2 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/SecondLevelDomains.js b/src/SecondLevelDomains.js index 2396a15b..8b78b39c 100644 --- a/src/SecondLevelDomains.js +++ b/src/SecondLevelDomains.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * Second Level Domain (SLD) Support * - * Version: 1.19.1 + * Version: 1.19.2 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/URI.js b/src/URI.js index bd23fc66..1dceb2f3 100644 --- a/src/URI.js +++ b/src/URI.js @@ -1,7 +1,7 @@ /*! * URI.js - Mutating URLs * - * Version: 1.19.1 + * Version: 1.19.2 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ @@ -81,7 +81,7 @@ return /^[0-9]+$/.test(value); } - URI.version = '1.19.1'; + URI.version = '1.19.2'; var p = URI.prototype; var hasOwn = Object.prototype.hasOwnProperty; diff --git a/src/URI.min.js b/src/URI.min.js index 75c8a4c7..caf3855f 100644 --- a/src/URI.min.js +++ b/src/URI.min.js @@ -1,4 +1,4 @@ -/*! URI.js v1.19.1 http://medialize.github.io/URI.js/ */ +/*! URI.js v1.19.2 http://medialize.github.io/URI.js/ */ /* build contains: IPv6.js, punycode.js, SecondLevelDomains.js, URI.js, URITemplate.js */ (function(f,n){"object"===typeof module&&module.exports?module.exports=n():"function"===typeof define&&define.amd?define(n):f.IPv6=n(f)})(this,function(f){var n=f&&f.IPv6;return{best:function(h){h=h.toLowerCase().split(":");var k=h.length,b=8;""===h[0]&&""===h[1]&&""===h[2]?(h.shift(),h.shift()):""===h[0]&&""===h[1]?h.shift():""===h[k-1]&&""===h[k-2]&&h.pop();k=h.length;-1!==h[k-1].indexOf(".")&&(b=7);var q;for(q=0;qf;f++)if("0"===k[0]&&1f&&(k=g,f=n)):"0"===h[q]&&(p=!0,g=q,n=1);n>f&&(k=g,f=n);1=k||k>=b-1)return null;var n=h.list[f.slice(b+1)];return!n||0>n.indexOf(" " (function(f,n){"object"===typeof module&&module.exports?module.exports=n(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"===typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],n):f.URI=n(f.punycode,f.IPv6,f.SecondLevelDomains,f)})(this,function(f,n,h,k){function b(a,c){var d=1<=arguments.length,l=2<=arguments.length;if(!(this instanceof b))return d?l?new b(a,c):new b(a):new b;if(void 0===a){if(d)throw new TypeError("undefined is not a valid argument for URI"); a="undefined"!==typeof location?location.href+"":""}if(null===a&&d)throw new TypeError("null is not a valid argument for URI");this.href(a);return void 0!==c?this.absoluteTo(c):this}function q(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function z(a){return void 0===a?"Undefined":String(Object.prototype.toString.call(a)).slice(8,-1)}function u(a){return"Array"===z(a)}function g(a,c){var d={},b;if("RegExp"===z(c))d=null;else if(u(c)){var m=0;for(b=c.length;m]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u2018\u2019]))/ig;b.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u201e\u2018\u2019]+$/,parens:/(\([^\)]*\)|\[[^\]]*\]|\{[^}]*\}|<[^>]*>)/g};b.defaultPorts={http:"80",https:"443",ftp:"21", @@ -38,39 +38,39 @@ l=(l+"").split(a);for(var e=0,g=l.length;eb)return a.charAt(0)===c.charAt(0)&&"/"===a.charAt(0)?"/":"";if("/"!==a.charAt(b)||"/"!==c.charAt(b))b=a.substring(0,b).lastIndexOf("/");return a.substring(0,b+1)};b.withinString=function(a,c,d){d||(d={});var l=d.start||b.findUri.start,m=d.end||b.findUri.end,e=d.trim||b.findUri.trim,g= -d.parens||b.findUri.parens,f=/[a-z0-9-]=["']?$/i;for(l.lastIndex=0;;){var h=l.exec(a);if(!h)break;var k=h.index;if(d.ignoreHtml){var p=a.slice(Math.max(k-3,0),k);if(p&&f.test(p))continue}var n=k+a.slice(k).search(m);p=a.slice(k,n);for(n=-1;;){var r=g.exec(p);if(!r)break;n=Math.max(n,r.index+r[0].length)}p=-1c))throw new TypeError('Port "'+a+'" is not a valid port');}};b.noConflict=function(a){if(a)return a={URI:this.noConflict()},k.URITemplate&&"function"===typeof k.URITemplate.noConflict&&(a.URITemplate=k.URITemplate.noConflict()),k.IPv6&&"function"===typeof k.IPv6.noConflict&&(a.IPv6=k.IPv6.noConflict()),k.SecondLevelDomains&&"function"===typeof k.SecondLevelDomains.noConflict&&(a.SecondLevelDomains=k.SecondLevelDomains.noConflict()), -a;k.URI===this&&(k.URI=w);return this};e.build=function(a){if(!0===a)this._deferred_build=!0;else if(void 0===a||this._deferred_build)this._string=b.build(this._parts),this._deferred_build=!1;return this};e.clone=function(){return new b(this)};e.valueOf=e.toString=function(){return this.build(!1)._string};e.protocol=r("protocol");e.username=r("username");e.password=r("password");e.hostname=r("hostname");e.port=r("port");e.query=C("query","?");e.fragment=C("fragment","#");e.search=function(a,c){var b= -this.query(a,c);return"string"===typeof b&&b.length?"?"+b:b};e.hash=function(a,c){var b=this.fragment(a,c);return"string"===typeof b&&b.length?"#"+b:b};e.pathname=function(a,c){if(void 0===a||!0===a){var d=this._parts.path||(this._parts.hostname?"/":"");return a?(this._parts.urn?b.decodeUrnPath:b.decodePath)(d):d}this._parts.path=this._parts.urn?a?b.recodeUrnPath(a):"":a?b.recodePath(a):"/";this.build(!c);return this};e.path=e.pathname;e.href=function(a,c){var d;if(void 0===a)return this.toString(); -this._string="";this._parts=b._parts();var l=a instanceof b,e="object"===typeof a&&(a.hostname||a.path||a.pathname);a.nodeName&&(e=b.getDomAttribute(a),a=a[e]||"",e=!1);!l&&e&&void 0!==a.pathname&&(a=a.toString());if("string"===typeof a||a instanceof String)this._parts=b.parse(String(a),this._parts);else if(l||e){l=l?a._parts:a;for(d in l)"query"!==d&&t.call(this._parts,d)&&(this._parts[d]=l[d]);l.query&&this.query(l.query,!1)}else throw new TypeError("invalid input");this.build(!c);return this}; -e.is=function(a){var c=!1,d=!1,e=!1,m=!1,g=!1,f=!1,k=!1,p=!this._parts.urn;this._parts.hostname&&(p=!1,d=b.ip4_expression.test(this._parts.hostname),e=b.ip6_expression.test(this._parts.hostname),c=d||e,g=(m=!c)&&h&&h.has(this._parts.hostname),f=m&&b.idn_expression.test(this._parts.hostname),k=m&&b.punycode_expression.test(this._parts.hostname));switch(a.toLowerCase()){case "relative":return p;case "absolute":return!p;case "domain":case "name":return m;case "sld":return g;case "ip":return c;case "ip4":case "ipv4":case "inet4":return d; -case "ip6":case "ipv6":case "inet6":return e;case "idn":return f;case "url":return!this._parts.urn;case "urn":return!!this._parts.urn;case "punycode":return k}return null};var G=e.protocol,H=e.port,I=e.hostname;e.protocol=function(a,c){if(a&&(a=a.replace(/:(\/\/)?$/,""),!a.match(b.protocol_expression)))throw new TypeError('Protocol "'+a+"\" contains characters other than [A-Z0-9.+-] or doesn't start with [A-Z]");return G.call(this,a,c)};e.scheme=e.protocol;e.port=function(a,c){if(this._parts.urn)return void 0=== -a?"":this;void 0!==a&&(0===a&&(a=null),a&&(a+="",":"===a.charAt(0)&&(a=a.substring(1)),b.ensureValidPort(a)));return H.call(this,a,c)};e.hostname=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0!==a){var d={preventInvalidHostname:this._parts.preventInvalidHostname};if("/"!==b.parseHost(a,d))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]');a=d.hostname;this._parts.preventInvalidHostname&&b.ensureValidHostname(a,this._parts.protocol)}return I.call(this, -a,c)};e.origin=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){var d=this.protocol();return this.authority()?(d?d+"://":"")+this.authority():""}d=b(a);this.protocol(d.protocol()).authority(d.authority()).build(!c);return this};e.host=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a)return this._parts.hostname?b.buildHost(this._parts):"";if("/"!==b.parseHost(a,this._parts))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]'); -this.build(!c);return this};e.authority=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a)return this._parts.hostname?b.buildAuthority(this._parts):"";if("/"!==b.parseAuthority(a,this._parts))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]');this.build(!c);return this};e.userinfo=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){var d=b.buildUserinfo(this._parts);return d?d.substring(0,d.length-1):d}"@"!==a[a.length-1]&& -(a+="@");b.parseUserinfo(a,this._parts);this.build(!c);return this};e.resource=function(a,c){if(void 0===a)return this.path()+this.search()+this.hash();var d=b.parse(a);this._parts.path=d.path;this._parts.query=d.query;this._parts.fragment=d.fragment;this.build(!c);return this};e.subdomain=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var d=this._parts.hostname.length-this.domain().length-1;return this._parts.hostname.substring(0, -d)||""}d=this._parts.hostname.length-this.domain().length;d=this._parts.hostname.substring(0,d);d=new RegExp("^"+q(d));a&&"."!==a.charAt(a.length-1)&&(a+=".");if(-1!==a.indexOf(":"))throw new TypeError("Domains cannot contain colons");a&&b.ensureValidHostname(a,this._parts.protocol);this._parts.hostname=this._parts.hostname.replace(d,a);this.build(!c);return this};e.domain=function(a,c){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(c=a,a=void 0);if(void 0===a){if(!this._parts.hostname|| -this.is("IP"))return"";var d=this._parts.hostname.match(/\./g);if(d&&2>d.length)return this._parts.hostname;d=this._parts.hostname.length-this.tld(c).length-1;d=this._parts.hostname.lastIndexOf(".",d-1)+1;return this._parts.hostname.substring(d)||""}if(!a)throw new TypeError("cannot set domain empty");if(-1!==a.indexOf(":"))throw new TypeError("Domains cannot contain colons");b.ensureValidHostname(a,this._parts.protocol);!this._parts.hostname||this.is("IP")?this._parts.hostname=a:(d=new RegExp(q(this.domain())+ -"$"),this._parts.hostname=this._parts.hostname.replace(d,a));this.build(!c);return this};e.tld=function(a,c){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(c=a,a=void 0);if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var b=this._parts.hostname.lastIndexOf(".");b=this._parts.hostname.substring(b+1);return!0!==c&&h&&h.list[b.toLowerCase()]?h.get(this._parts.hostname)||b:b}if(a)if(a.match(/[^a-zA-Z0-9-]/))if(h&&h.is(a))b=new RegExp(q(this.tld())+"$"),this._parts.hostname= -this._parts.hostname.replace(b,a);else throw new TypeError('TLD "'+a+'" contains characters other than [A-Z0-9]');else{if(!this._parts.hostname||this.is("IP"))throw new ReferenceError("cannot set TLD on non-domain host");b=new RegExp(q(this.tld())+"$");this._parts.hostname=this._parts.hostname.replace(b,a)}else throw new TypeError("cannot set TLD empty");this.build(!c);return this};e.directory=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path&& -!this._parts.hostname)return"";if("/"===this._parts.path)return"/";var d=this._parts.path.length-this.filename().length-1;d=this._parts.path.substring(0,d)||(this._parts.hostname?"/":"");return a?b.decodePath(d):d}d=this._parts.path.length-this.filename().length;d=this._parts.path.substring(0,d);d=new RegExp("^"+q(d));this.is("relative")||(a||(a="/"),"/"!==a.charAt(0)&&(a="/"+a));a&&"/"!==a.charAt(a.length-1)&&(a+="/");a=b.recodePath(a);this._parts.path=this._parts.path.replace(d,a);this.build(!c); -return this};e.filename=function(a,c){if(this._parts.urn)return void 0===a?"":this;if("string"!==typeof a){if(!this._parts.path||"/"===this._parts.path)return"";var d=this._parts.path.lastIndexOf("/");d=this._parts.path.substring(d+1);return a?b.decodePathSegment(d):d}d=!1;"/"===a.charAt(0)&&(a=a.substring(1));a.match(/\.?\//)&&(d=!0);var e=new RegExp(q(this.filename())+"$");a=b.recodePath(a);this._parts.path=this._parts.path.replace(e,a);d?this.normalizePath(c):this.build(!c);return this};e.suffix= -function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path||"/"===this._parts.path)return"";var d=this.filename(),e=d.lastIndexOf(".");if(-1===e)return"";d=d.substring(e+1);d=/^[a-z0-9%]+$/i.test(d)?d:"";return a?b.decodePathSegment(d):d}"."===a.charAt(0)&&(a=a.substring(1));if(d=this.suffix())e=a?new RegExp(q(d)+"$"):new RegExp(q("."+d)+"$");else{if(!a)return this;this._parts.path+="."+b.recodePath(a)}e&&(a=b.recodePath(a),this._parts.path=this._parts.path.replace(e, -a));this.build(!c);return this};e.segment=function(a,c,b){var d=this._parts.urn?":":"/",e=this.path(),g="/"===e.substring(0,1);e=e.split(d);void 0!==a&&"number"!==typeof a&&(b=c,c=a,a=void 0);if(void 0!==a&&"number"!==typeof a)throw Error('Bad segment "'+a+'", must be 0-based integer');g&&e.shift();0>a&&(a=Math.max(e.length+a,0));if(void 0===c)return void 0===a?e:e[a];if(null===a||void 0===e[a])if(u(c)){e=[];a=0;for(var f=c.length;ab)return a.charAt(0)===c.charAt(0)&&"/"===a.charAt(0)?"/":"";if("/"!==a.charAt(b)||"/"!==c.charAt(b))b=a.substring(0,b).lastIndexOf("/");return a.substring(0,b+1)};b.withinString=function(a,c,d){d||(d={});var l=d.start||b.findUri.start,e=d.end||b.findUri.end,g=d.trim||b.findUri.trim,f=d.parens||b.findUri.parens,h=/[a-z0-9-]=["']?$/i; +for(l.lastIndex=0;;){var k=l.exec(a);if(!k)break;var p=k.index;if(d.ignoreHtml){var n=a.slice(Math.max(p-3,0),p);if(n&&h.test(n))continue}var r=p+a.slice(p).search(e);n=a.slice(p,r);for(r=-1;;){var q=f.exec(n);if(!q)break;r=Math.max(r,q.index+q[0].length)}n=-1c))throw new TypeError('Port "'+a+'" is not a valid port');}};b.noConflict=function(a){if(a)return a={URI:this.noConflict()},k.URITemplate&&"function"===typeof k.URITemplate.noConflict&&(a.URITemplate=k.URITemplate.noConflict()),k.IPv6&&"function"===typeof k.IPv6.noConflict&&(a.IPv6=k.IPv6.noConflict()),k.SecondLevelDomains&&"function"===typeof k.SecondLevelDomains.noConflict&&(a.SecondLevelDomains=k.SecondLevelDomains.noConflict()),a;k.URI===this&&(k.URI= +w);return this};e.build=function(a){if(!0===a)this._deferred_build=!0;else if(void 0===a||this._deferred_build)this._string=b.build(this._parts),this._deferred_build=!1;return this};e.clone=function(){return new b(this)};e.valueOf=e.toString=function(){return this.build(!1)._string};e.protocol=r("protocol");e.username=r("username");e.password=r("password");e.hostname=r("hostname");e.port=r("port");e.query=C("query","?");e.fragment=C("fragment","#");e.search=function(a,c){var b=this.query(a,c);return"string"=== +typeof b&&b.length?"?"+b:b};e.hash=function(a,c){var b=this.fragment(a,c);return"string"===typeof b&&b.length?"#"+b:b};e.pathname=function(a,c){if(void 0===a||!0===a){var d=this._parts.path||(this._parts.hostname?"/":"");return a?(this._parts.urn?b.decodeUrnPath:b.decodePath)(d):d}this._parts.path=this._parts.urn?a?b.recodeUrnPath(a):"":a?b.recodePath(a):"/";this.build(!c);return this};e.path=e.pathname;e.href=function(a,c){var d;if(void 0===a)return this.toString();this._string="";this._parts=b._parts(); +var l=a instanceof b,e="object"===typeof a&&(a.hostname||a.path||a.pathname);a.nodeName&&(e=b.getDomAttribute(a),a=a[e]||"",e=!1);!l&&e&&void 0!==a.pathname&&(a=a.toString());if("string"===typeof a||a instanceof String)this._parts=b.parse(String(a),this._parts);else if(l||e){l=l?a._parts:a;for(d in l)"query"!==d&&t.call(this._parts,d)&&(this._parts[d]=l[d]);l.query&&this.query(l.query,!1)}else throw new TypeError("invalid input");this.build(!c);return this};e.is=function(a){var c=!1,d=!1,e=!1,m=!1, +g=!1,f=!1,k=!1,p=!this._parts.urn;this._parts.hostname&&(p=!1,d=b.ip4_expression.test(this._parts.hostname),e=b.ip6_expression.test(this._parts.hostname),c=d||e,g=(m=!c)&&h&&h.has(this._parts.hostname),f=m&&b.idn_expression.test(this._parts.hostname),k=m&&b.punycode_expression.test(this._parts.hostname));switch(a.toLowerCase()){case "relative":return p;case "absolute":return!p;case "domain":case "name":return m;case "sld":return g;case "ip":return c;case "ip4":case "ipv4":case "inet4":return d;case "ip6":case "ipv6":case "inet6":return e; +case "idn":return f;case "url":return!this._parts.urn;case "urn":return!!this._parts.urn;case "punycode":return k}return null};var G=e.protocol,H=e.port,I=e.hostname;e.protocol=function(a,c){if(a&&(a=a.replace(/:(\/\/)?$/,""),!a.match(b.protocol_expression)))throw new TypeError('Protocol "'+a+"\" contains characters other than [A-Z0-9.+-] or doesn't start with [A-Z]");return G.call(this,a,c)};e.scheme=e.protocol;e.port=function(a,c){if(this._parts.urn)return void 0===a?"":this;void 0!==a&&(0===a&& +(a=null),a&&(a+="",":"===a.charAt(0)&&(a=a.substring(1)),b.ensureValidPort(a)));return H.call(this,a,c)};e.hostname=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0!==a){var d={preventInvalidHostname:this._parts.preventInvalidHostname};if("/"!==b.parseHost(a,d))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]');a=d.hostname;this._parts.preventInvalidHostname&&b.ensureValidHostname(a,this._parts.protocol)}return I.call(this,a,c)};e.origin=function(a, +c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){var d=this.protocol();return this.authority()?(d?d+"://":"")+this.authority():""}d=b(a);this.protocol(d.protocol()).authority(d.authority()).build(!c);return this};e.host=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a)return this._parts.hostname?b.buildHost(this._parts):"";if("/"!==b.parseHost(a,this._parts))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]');this.build(!c);return this}; +e.authority=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a)return this._parts.hostname?b.buildAuthority(this._parts):"";if("/"!==b.parseAuthority(a,this._parts))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]');this.build(!c);return this};e.userinfo=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){var d=b.buildUserinfo(this._parts);return d?d.substring(0,d.length-1):d}"@"!==a[a.length-1]&&(a+="@");b.parseUserinfo(a, +this._parts);this.build(!c);return this};e.resource=function(a,c){if(void 0===a)return this.path()+this.search()+this.hash();var d=b.parse(a);this._parts.path=d.path;this._parts.query=d.query;this._parts.fragment=d.fragment;this.build(!c);return this};e.subdomain=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var d=this._parts.hostname.length-this.domain().length-1;return this._parts.hostname.substring(0,d)||""}d=this._parts.hostname.length- +this.domain().length;d=this._parts.hostname.substring(0,d);d=new RegExp("^"+q(d));a&&"."!==a.charAt(a.length-1)&&(a+=".");if(-1!==a.indexOf(":"))throw new TypeError("Domains cannot contain colons");a&&b.ensureValidHostname(a,this._parts.protocol);this._parts.hostname=this._parts.hostname.replace(d,a);this.build(!c);return this};e.domain=function(a,c){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(c=a,a=void 0);if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var d= +this._parts.hostname.match(/\./g);if(d&&2>d.length)return this._parts.hostname;d=this._parts.hostname.length-this.tld(c).length-1;d=this._parts.hostname.lastIndexOf(".",d-1)+1;return this._parts.hostname.substring(d)||""}if(!a)throw new TypeError("cannot set domain empty");if(-1!==a.indexOf(":"))throw new TypeError("Domains cannot contain colons");b.ensureValidHostname(a,this._parts.protocol);!this._parts.hostname||this.is("IP")?this._parts.hostname=a:(d=new RegExp(q(this.domain())+"$"),this._parts.hostname= +this._parts.hostname.replace(d,a));this.build(!c);return this};e.tld=function(a,c){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(c=a,a=void 0);if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var b=this._parts.hostname.lastIndexOf(".");b=this._parts.hostname.substring(b+1);return!0!==c&&h&&h.list[b.toLowerCase()]?h.get(this._parts.hostname)||b:b}if(a)if(a.match(/[^a-zA-Z0-9-]/))if(h&&h.is(a))b=new RegExp(q(this.tld())+"$"),this._parts.hostname=this._parts.hostname.replace(b, +a);else throw new TypeError('TLD "'+a+'" contains characters other than [A-Z0-9]');else{if(!this._parts.hostname||this.is("IP"))throw new ReferenceError("cannot set TLD on non-domain host");b=new RegExp(q(this.tld())+"$");this._parts.hostname=this._parts.hostname.replace(b,a)}else throw new TypeError("cannot set TLD empty");this.build(!c);return this};e.directory=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path&&!this._parts.hostname)return""; +if("/"===this._parts.path)return"/";var d=this._parts.path.length-this.filename().length-1;d=this._parts.path.substring(0,d)||(this._parts.hostname?"/":"");return a?b.decodePath(d):d}d=this._parts.path.length-this.filename().length;d=this._parts.path.substring(0,d);d=new RegExp("^"+q(d));this.is("relative")||(a||(a="/"),"/"!==a.charAt(0)&&(a="/"+a));a&&"/"!==a.charAt(a.length-1)&&(a+="/");a=b.recodePath(a);this._parts.path=this._parts.path.replace(d,a);this.build(!c);return this};e.filename=function(a, +c){if(this._parts.urn)return void 0===a?"":this;if("string"!==typeof a){if(!this._parts.path||"/"===this._parts.path)return"";var d=this._parts.path.lastIndexOf("/");d=this._parts.path.substring(d+1);return a?b.decodePathSegment(d):d}d=!1;"/"===a.charAt(0)&&(a=a.substring(1));a.match(/\.?\//)&&(d=!0);var e=new RegExp(q(this.filename())+"$");a=b.recodePath(a);this._parts.path=this._parts.path.replace(e,a);d?this.normalizePath(c):this.build(!c);return this};e.suffix=function(a,c){if(this._parts.urn)return void 0=== +a?"":this;if(void 0===a||!0===a){if(!this._parts.path||"/"===this._parts.path)return"";var d=this.filename(),e=d.lastIndexOf(".");if(-1===e)return"";d=d.substring(e+1);d=/^[a-z0-9%]+$/i.test(d)?d:"";return a?b.decodePathSegment(d):d}"."===a.charAt(0)&&(a=a.substring(1));if(d=this.suffix())e=a?new RegExp(q(d)+"$"):new RegExp(q("."+d)+"$");else{if(!a)return this;this._parts.path+="."+b.recodePath(a)}e&&(a=b.recodePath(a),this._parts.path=this._parts.path.replace(e,a));this.build(!c);return this};e.segment= +function(a,c,b){var d=this._parts.urn?":":"/",e=this.path(),g="/"===e.substring(0,1);e=e.split(d);void 0!==a&&"number"!==typeof a&&(b=c,c=a,a=void 0);if(void 0!==a&&"number"!==typeof a)throw Error('Bad segment "'+a+'", must be 0-based integer');g&&e.shift();0>a&&(a=Math.max(e.length+a,0));if(void 0===c)return void 0===a?e:e[a];if(null===a||void 0===e[a])if(u(c)){e=[];a=0;for(var f=c.length;a Date: Sun, 20 Dec 2020 12:17:05 +0100 Subject: [PATCH 40/44] fix(parse): treat backslash as forwardslash in authority --- src/URI.js | 6 ++++-- test/urls.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/URI.js b/src/URI.js index 1dceb2f3..cedcbbd4 100644 --- a/src/URI.js +++ b/src/URI.js @@ -612,12 +612,14 @@ }; URI.parseUserinfo = function(string, parts) { // extract username:password + var firstBackSlash = string.indexOf('\\'); var firstSlash = string.indexOf('/'); + var slash = firstBackSlash === -1 ? firstSlash : (firstSlash !== -1 ? Math.min(firstBackSlash, firstSlash): firstSlash) var pos = string.lastIndexOf('@', firstSlash > -1 ? firstSlash : string.length - 1); var t; - // authority@ must come before /path - if (pos > -1 && (firstSlash === -1 || pos < firstSlash)) { + // authority@ must come before /path or \path + if (pos > -1 && (slash === -1 || pos < slash)) { t = string.substring(0, pos).split(':'); parts.username = t[0] ? URI.decode(t[0]) : null; t.shift(); diff --git a/test/urls.js b/test/urls.js index 61d36771..5e0c06eb 100644 --- a/test/urls.js +++ b/test/urls.js @@ -1984,6 +1984,55 @@ var urls = [{ idn: false, punycode: false } + }, { + name: 'backslashes authority', + url: 'https://attacker.com\\@example.com/some/directory/file.html?query=string#fragment', + _url: 'https://attacker.com/@example.com/some/directory/file.html?query=string#fragment', + parts: { + protocol: 'https', + username: null, + password: null, + hostname: 'attacker.com', + port: null, + path: '/@example.com/some/directory/file.html', + query: 'query=string', + fragment: 'fragment' + }, + accessors: { + protocol: 'https', + username: '', + password: '', + port: '', + path: '/@example.com/some/directory/file.html', + query: 'query=string', + fragment: 'fragment', + resource: '/@example.com/some/directory/file.html?query=string#fragment', + authority: 'attacker.com', + origin: 'https://attacker.com', + userinfo: '', + subdomain: '', + domain: 'attacker.com', + tld: 'com', + directory: '/@example.com/some/directory', + filename: 'file.html', + suffix: 'html', + hash: '#fragment', + search: '?query=string', + host: 'attacker.com', + hostname: 'attacker.com' + }, + is: { + urn: false, + url: true, + relative: false, + name: true, + sld: false, + ip: false, + ip4: false, + ip6: false, + idn: false, + punycode: false + } } ]; From d7064ab9acbbdf8d8acc35d9dc2454cf1606ff98 Mon Sep 17 00:00:00 2001 From: Rodney Rehm Date: Sun, 20 Dec 2020 12:54:53 +0100 Subject: [PATCH 41/44] chore(build): bumping to version 1.19.3 --- CHANGELOG.md | 3 + bower.json | 2 +- build.js | 2 +- package.json | 2 +- src/IPv6.js | 2 +- src/SecondLevelDomains.js | 2 +- src/URI.js | 4 +- src/URI.min.js | 165 ++++++++++++++++++++------------------ src/URITemplate.js | 2 +- src/jquery.URI.js | 2 +- src/jquery.URI.min.js | 2 +- 11 files changed, 98 insertions(+), 90 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c32e2be4..f0319e94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ The release notes tracked in this document are also made available on the [releases page](https://github.com/medialize/URI.js/releases) +### 1.19.3 (December 20th 2020) ### + +* **SECURITY** fixing [`URI.parseAuthority()`](http://medialize.github.io/URI.js/docs.html#static-parseAuthority) to rewrite `\` to `/` as Node and Browsers do - disclosed privately, relates to [Issue #233](https://github.com/medialize/URI.js/pull/233) ### 1.19.2 (October 20th 2019) ### * fixing [`URI.build()`](http://medialize.github.io/URI.js/docs.html#static-build) to properly handle relative paths when a scheme is given - [Issue #387](https://github.com/medialize/URI.js/issues/387) diff --git a/bower.json b/bower.json index 62c19c08..e9da2366 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "urijs", - "version": "1.19.2", + "version": "1.19.3", "main": "src/URI.js", "ignore": [ ".*", diff --git a/build.js b/build.js index 0a0a1fb7..f25e6286 100644 --- a/build.js +++ b/build.js @@ -29,7 +29,7 @@ function build(files) { output_format: "text", output_info: "compiled_code" }, function(data) { - var code = "/*! URI.js v1.19.2 http://medialize.github.io/URI.js/ */\n/* build contains: " + files.join(', ') + " */\n" + data; + var code = "/*! URI.js v1.19.3 http://medialize.github.io/URI.js/ */\n/* build contains: " + files.join(', ') + " */\n" + data; $progress.hide(); $out.val(code).parent().show(); $out.prev().find('a').remove(); diff --git a/package.json b/package.json index 06050f5e..f25b0067 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "urijs", - "version": "1.19.2", + "version": "1.19.3", "title": "URI.js - Mutating URLs", "author": { "name": "Rodney Rehm", diff --git a/src/IPv6.js b/src/IPv6.js index 31eeffb2..80931d5a 100644 --- a/src/IPv6.js +++ b/src/IPv6.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * IPv6 Support * - * Version: 1.19.2 + * Version: 1.19.3 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/SecondLevelDomains.js b/src/SecondLevelDomains.js index 8b78b39c..648b5087 100644 --- a/src/SecondLevelDomains.js +++ b/src/SecondLevelDomains.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * Second Level Domain (SLD) Support * - * Version: 1.19.2 + * Version: 1.19.3 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/URI.js b/src/URI.js index cedcbbd4..715c097e 100644 --- a/src/URI.js +++ b/src/URI.js @@ -1,7 +1,7 @@ /*! * URI.js - Mutating URLs * - * Version: 1.19.2 + * Version: 1.19.3 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ @@ -81,7 +81,7 @@ return /^[0-9]+$/.test(value); } - URI.version = '1.19.2'; + URI.version = '1.19.3'; var p = URI.prototype; var hasOwn = Object.prototype.hasOwnProperty; diff --git a/src/URI.min.js b/src/URI.min.js index caf3855f..d515ae5e 100644 --- a/src/URI.min.js +++ b/src/URI.min.js @@ -1,14 +1,14 @@ -/*! URI.js v1.19.2 http://medialize.github.io/URI.js/ */ -/* build contains: IPv6.js, punycode.js, SecondLevelDomains.js, URI.js, URITemplate.js */ -(function(f,n){"object"===typeof module&&module.exports?module.exports=n():"function"===typeof define&&define.amd?define(n):f.IPv6=n(f)})(this,function(f){var n=f&&f.IPv6;return{best:function(h){h=h.toLowerCase().split(":");var k=h.length,b=8;""===h[0]&&""===h[1]&&""===h[2]?(h.shift(),h.shift()):""===h[0]&&""===h[1]?h.shift():""===h[k-1]&&""===h[k-2]&&h.pop();k=h.length;-1!==h[k-1].indexOf(".")&&(b=7);var q;for(q=0;qf;f++)if("0"===k[0]&&1f&&(k=g,f=n)):"0"===h[q]&&(p=!0,g=q,n=1);n>f&&(k=g,f=n);1=f&&g>>10&1023|55296),b=56320|b&1023);return e+=t(b)}).join("")}function z(b,e){return b+22+75*(26>b)-((0!=e)<<5)}function u(b,g,h){var f=0;b=h?e(b/700):b>>1;for(b+=e(b/g);455l&&(l=0);for(c=0;c=h&&n("invalid-input");var x=b.charCodeAt(l++); -x=10>x-48?x-22:26>x-65?x-65:26>x-97?x-97:36;(36<=x||x>e((2147483647-f)/m))&&n("overflow");f+=x*m;var p=d<=a?1:d>=a+26?26:d-a;if(xe(2147483647/x)&&n("overflow");m*=x}m=g.length+1;a=u(f-c,m,0==c);e(f/m)>2147483647-k&&n("overflow");k+=e(f/m);f%=m;g.splice(f++,0,k)}return q(g)}function p(g){var h,f,k,p=[];g=b(g);var a=g.length;var c=128;var d=0;var l=72;for(k=0;km&&p.push(t(m))}for((h=f=p.length)&&p.push("-");h=c&& -me((2147483647-d)/q)&&n("overflow");d+=(x-c)*q;c=x;for(k=0;k=l+26?26:x-l;if(r= 0x80 (not a basic code point)","invalid-input":"Invalid input"},e=Math.floor,t=String.fromCharCode,y;var v={version:"1.3.2",ucs2:{decode:b,encode:q},decode:g,encode:p,toASCII:function(b){return k(b,function(b){return r.test(b)?"xn--"+p(b):b})},toUnicode:function(b){return k(b,function(b){return E.test(b)?g(b.slice(4).toLowerCase()): -b})}};if("function"==typeof define&&"object"==typeof define.amd&&define.amd)define("punycode",function(){return v});else if(D&&A)if(module.exports==D)A.exports=v;else for(y in v)v.hasOwnProperty(y)&&(D[y]=v[y]);else f.punycode=v})(this); -(function(f,n){"object"===typeof module&&module.exports?module.exports=n():"function"===typeof define&&define.amd?define(n):f.SecondLevelDomains=n(f)})(this,function(f){var n=f&&f.SecondLevelDomains,h={list:{ac:" com gov mil net org ",ae:" ac co gov mil name net org pro sch ",af:" com edu gov net org ",al:" com edu gov mil net org ",ao:" co ed gv it og pb ",ar:" com edu gob gov int mil net org tur ",at:" ac co gv or ",au:" asn com csiro edu gov id net org ",ba:" co com edu gov mil net org rs unbi unmo unsa untz unze ", +/*! URI.js v1.19.3 http://medialize.github.io/URI.js/ */ +/* build contains: IPv6.js, punycode.js, SecondLevelDomains.js, URI.js, URITemplate.js, jquery.URI.js */ +(function(m,w){"object"===typeof module&&module.exports?module.exports=w():"function"===typeof define&&define.amd?define(w):m.IPv6=w(m)})(this,function(m){var w=m&&m.IPv6;return{best:function(k){k=k.toLowerCase().split(":");var p=k.length,d=8;""===k[0]&&""===k[1]&&""===k[2]?(k.shift(),k.shift()):""===k[0]&&""===k[1]?k.shift():""===k[p-1]&&""===k[p-2]&&k.pop();p=k.length;-1!==k[p-1].indexOf(".")&&(d=7);var v;for(v=0;vE;E++)if("0"===p[0]&&1E&&(p=l,E=A)):"0"===k[v]&&(r=!0,l=v,A=1);A>E&&(p=l,E=A);1=K&&H>>10&1023|55296),y=56320|y&1023);return H+=g(y)}).join("")}function E(n,y,H){var C=0;n=H?z(n/700):n>>1;for(n+=z(n/y);455c&&(c=0);for(a=0;a=H&&w("invalid-input");var f=n.charCodeAt(c++);f=10>f-48?f-22:26>f-65?f-65:26>f-97?f-97:36; +(36<=f||f>z((2147483647-C)/e))&&w("overflow");C+=f*e;var t=b<=M?1:b>=M+26?26:b-M;if(fz(2147483647/f)&&w("overflow");e*=f}e=y.length+1;M=E(C-a,e,0==a);z(C/e)>2147483647-K&&w("overflow");K+=z(C/e);C%=e;y.splice(C++,0,K)}return v(y)}function l(n){var y,H,C,K=[];n=d(n);var M=n.length;var a=128;var b=0;var c=72;for(C=0;Ce&&K.push(g(e))}for((y=H=K.length)&&K.push("-");y=a&&ez((2147483647-b)/t)&& +w("overflow");b+=(f-a)*t;a=f;for(C=0;C=c+26?26:f-c;if(De)-0));D=z(J/D)}K.push(g(D+22+75*(26>D)-0));c=E(b,t,y==H);b=0;++y}++b;++a}return K.join("")}var r="object"==typeof exports&&exports&&!exports.nodeType&&exports,F="object"==typeof module&&module&&!module.nodeType&&module,h="object"==typeof global&&global;if(h.global===h||h.window===h|| +h.self===h)m=h;var q=/^xn--/,u=/[^\x20-\x7E]/,x=/[\x2E\u3002\uFF0E\uFF61]/g,B={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},z=Math.floor,g=String.fromCharCode,G;var I={version:"1.3.2",ucs2:{decode:d,encode:v},decode:A,encode:l,toASCII:function(n){return p(n,function(y){return u.test(y)?"xn--"+l(y):y})},toUnicode:function(n){return p(n,function(y){return q.test(y)?A(y.slice(4).toLowerCase()): +y})}};if("function"==typeof define&&"object"==typeof define.amd&&define.amd)define("punycode",function(){return I});else if(r&&F)if(module.exports==r)F.exports=I;else for(G in I)I.hasOwnProperty(G)&&(r[G]=I[G]);else m.punycode=I})(this); +(function(m,w){"object"===typeof module&&module.exports?module.exports=w():"function"===typeof define&&define.amd?define(w):m.SecondLevelDomains=w(m)})(this,function(m){var w=m&&m.SecondLevelDomains,k={list:{ac:" com gov mil net org ",ae:" ac co gov mil name net org pro sch ",af:" com edu gov net org ",al:" com edu gov mil net org ",ao:" co ed gv it og pb ",ar:" com edu gob gov int mil net org tur ",at:" ac co gv or ",au:" asn com csiro edu gov id net org ",ba:" co com edu gov mil net org rs unbi unmo unsa untz unze ", bb:" biz co com edu gov info net org store tv ",bh:" biz cc com edu gov info net org ",bn:" com edu gov net org ",bo:" com edu gob gov int mil net org tv ",br:" adm adv agr am arq art ato b bio blog bmd cim cng cnt com coop ecn edu eng esp etc eti far flog fm fnd fot fst g12 ggf gov imb ind inf jor jus lel mat med mil mus net nom not ntr odo org ppg pro psc psi qsl rec slg srv tmp trd tur tv vet vlog wiki zlg ",bs:" com edu gov net org ",bz:" du et om ov rg ",ca:" ab bc mb nb nf nl ns nt nu on pe qc sk yk ", ck:" biz co edu gen gov info net org ",cn:" ac ah bj com cq edu fj gd gov gs gx gz ha hb he hi hl hn jl js jx ln mil net nm nx org qh sc sd sh sn sx tj tw xj xz yn zj ",co:" com edu gov mil net nom org ",cr:" ac c co ed fi go or sa ",cy:" ac biz com ekloges gov ltd name net org parliament press pro tm ","do":" art com edu gob gov mil net org sld web ",dz:" art asso com edu gov net org pol ",ec:" com edu fin gov info med mil net org pro ",eg:" com edu eun gov mil name net org sci ",er:" com edu gov ind mil net org rochest w ", es:" com edu gob nom org ",et:" biz com edu gov info name net org ",fj:" ac biz com info mil name net org pro ",fk:" ac co gov net nom org ",fr:" asso com f gouv nom prd presse tm ",gg:" co net org ",gh:" com edu gov mil org ",gn:" ac com gov net org ",gr:" com edu gov mil net org ",gt:" com edu gob ind mil net org ",gu:" com edu gov net org ",hk:" com edu gov idv net org ",hu:" 2000 agrar bolt casino city co erotica erotika film forum games hotel info ingatlan jogasz konyvelo lakas media news org priv reklam sex shop sport suli szex tm tozsde utazas video ", @@ -21,73 +21,78 @@ tw:" club com ebiz edu game gov idv mil net org ",mu:" ac co com gov net or org rw:" ac co com edu gouv gov int mil net ",sa:" com edu gov med net org pub sch ",sd:" com edu gov info med net org tv ",se:" a ac b bd c d e f g h i k l m n o org p parti pp press r s t tm u w x y z ",sg:" com edu gov idn net org per ",sn:" art com edu gouv org perso univ ",sy:" com edu gov mil net news org ",th:" ac co go in mi net or ",tj:" ac biz co com edu go gov info int mil name net nic org test web ",tn:" agrinet com defense edunet ens fin gov ind info intl mincom nat net org perso rnrt rns rnu tourism ", tz:" ac co go ne or ",ua:" biz cherkassy chernigov chernovtsy ck cn co com crimea cv dn dnepropetrovsk donetsk dp edu gov if in ivano-frankivsk kh kharkov kherson khmelnitskiy kiev kirovograd km kr ks kv lg lugansk lutsk lviv me mk net nikolaev od odessa org pl poltava pp rovno rv sebastopol sumy te ternopil uzhgorod vinnica vn zaporizhzhe zhitomir zp zt ",ug:" ac co go ne or org sc ",uk:" ac bl british-library co cym gov govt icnet jet lea ltd me mil mod national-library-scotland nel net nhs nic nls org orgn parliament plc police sch scot soc ", us:" dni fed isa kids nsn ",uy:" com edu gub mil net org ",ve:" co com edu gob info mil net org web ",vi:" co com k12 net org ",vn:" ac biz com edu gov health info int name net org pro ",ye:" co com gov ltd me net org plc ",yu:" ac co edu gov org ",za:" ac agric alt bourse city co cybernet db edu gov grondar iaccess imt inca landesign law mil net ngo nis nom olivetti org pix school tm web ",zm:" ac co com edu gov net org sch ",com:"ar br cn de eu gb gr hu jpn kr no qc ru sa se uk us uy za ",net:"gb jp se uk ", -org:"ae",de:"com "},has:function(f){var b=f.lastIndexOf(".");if(0>=b||b>=f.length-1)return!1;var k=f.lastIndexOf(".",b-1);if(0>=k||k>=b-1)return!1;var n=h.list[f.slice(b+1)];return n?0<=n.indexOf(" "+f.slice(k+1,b)+" "):!1},is:function(f){var b=f.lastIndexOf(".");if(0>=b||b>=f.length-1||0<=f.lastIndexOf(".",b-1))return!1;var k=h.list[f.slice(b+1)];return k?0<=k.indexOf(" "+f.slice(0,b)+" "):!1},get:function(f){var b=f.lastIndexOf(".");if(0>=b||b>=f.length-1)return null;var k=f.lastIndexOf(".",b-1); -if(0>=k||k>=b-1)return null;var n=h.list[f.slice(b+1)];return!n||0>n.indexOf(" "+f.slice(k+1,b)+" ")?null:f.slice(k+1)},noConflict:function(){f.SecondLevelDomains===this&&(f.SecondLevelDomains=n);return this}};return h}); -(function(f,n){"object"===typeof module&&module.exports?module.exports=n(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"===typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],n):f.URI=n(f.punycode,f.IPv6,f.SecondLevelDomains,f)})(this,function(f,n,h,k){function b(a,c){var d=1<=arguments.length,l=2<=arguments.length;if(!(this instanceof b))return d?l?new b(a,c):new b(a):new b;if(void 0===a){if(d)throw new TypeError("undefined is not a valid argument for URI"); -a="undefined"!==typeof location?location.href+"":""}if(null===a&&d)throw new TypeError("null is not a valid argument for URI");this.href(a);return void 0!==c?this.absoluteTo(c):this}function q(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function z(a){return void 0===a?"Undefined":String(Object.prototype.toString.call(a)).slice(8,-1)}function u(a){return"Array"===z(a)}function g(a,c){var d={},b;if("RegExp"===z(c))d=null;else if(u(c)){var m=0;for(b=c.length;m]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u2018\u2019]))/ig;b.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u201e\u2018\u2019]+$/,parens:/(\([^\)]*\)|\[[^\]]*\]|\{[^}]*\}|<[^>]*>)/g};b.defaultPorts={http:"80",https:"443",ftp:"21", -gopher:"70",ws:"80",wss:"443"};b.hostProtocols=["http","https"];b.invalid_hostname_characters=/[^a-zA-Z0-9\.\-:_]/;b.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src",audio:"src",video:"src"};b.getDomAttribute=function(a){if(a&&a.nodeName){var c=a.nodeName.toLowerCase();if("input"!==c||"image"===a.type)return b.domAttributes[c]}};b.encode=E;b.decode=decodeURIComponent;b.iso8859= -function(){b.encode=escape;b.decode=unescape};b.unicode=function(){b.encode=E;b.decode=decodeURIComponent};b.characters={pathname:{encode:{expression:/%(24|26|2B|2C|3B|3D|3A|40)/ig,map:{"%24":"$","%26":"&","%2B":"+","%2C":",","%3B":";","%3D":"=","%3A":":","%40":"@"}},decode:{expression:/[\/\?#]/g,map:{"/":"%2F","?":"%3F","#":"%23"}}},reserved:{encode:{expression:/%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/ig,map:{"%3A":":","%2F":"/","%3F":"?","%23":"#","%5B":"[","%5D":"]","%40":"@", -"%21":"!","%24":"$","%26":"&","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"="}}},urnpath:{encode:{expression:/%(21|24|27|28|29|2A|2B|2C|3B|3D|40)/ig,map:{"%21":"!","%24":"$","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"=","%40":"@"}},decode:{expression:/[\/\?#:]/g,map:{"/":"%2F","?":"%3F","#":"%23",":":"%3A"}}}};b.encodeQuery=function(a,c){var d=b.encode(a+"");void 0===c&&(c=b.escapeQuerySpace);return c?d.replace(/%20/g,"+"):d};b.decodeQuery= -function(a,c){a+="";void 0===c&&(c=b.escapeQuerySpace);try{return b.decode(c?a.replace(/\+/g,"%20"):a)}catch(d){return a}};var y={encode:"encode",decode:"decode"},v,F=function(a,c){return function(d){try{return b[c](d+"").replace(b.characters[a][c].expression,function(d){return b.characters[a][c].map[d]})}catch(l){return d}}};for(v in y)b[v+"PathSegment"]=F("pathname",y[v]),b[v+"UrnPathSegment"]=F("urnpath",y[v]);y=function(a,c,d){return function(l){var m=d?function(a){return b[c](b[d](a))}:b[c]; -l=(l+"").split(a);for(var e=0,g=l.length;eb)return a.charAt(0)===c.charAt(0)&&"/"===a.charAt(0)?"/":"";if("/"!==a.charAt(b)||"/"!==c.charAt(b))b=a.substring(0,b).lastIndexOf("/");return a.substring(0,b+1)};b.withinString=function(a,c,d){d||(d={});var l=d.start||b.findUri.start,e=d.end||b.findUri.end,g=d.trim||b.findUri.trim,f=d.parens||b.findUri.parens,h=/[a-z0-9-]=["']?$/i; -for(l.lastIndex=0;;){var k=l.exec(a);if(!k)break;var p=k.index;if(d.ignoreHtml){var n=a.slice(Math.max(p-3,0),p);if(n&&h.test(n))continue}var r=p+a.slice(p).search(e);n=a.slice(p,r);for(r=-1;;){var q=f.exec(n);if(!q)break;r=Math.max(r,q.index+q[0].length)}n=-1c))throw new TypeError('Port "'+a+'" is not a valid port');}};b.noConflict=function(a){if(a)return a={URI:this.noConflict()},k.URITemplate&&"function"===typeof k.URITemplate.noConflict&&(a.URITemplate=k.URITemplate.noConflict()),k.IPv6&&"function"===typeof k.IPv6.noConflict&&(a.IPv6=k.IPv6.noConflict()),k.SecondLevelDomains&&"function"===typeof k.SecondLevelDomains.noConflict&&(a.SecondLevelDomains=k.SecondLevelDomains.noConflict()),a;k.URI===this&&(k.URI= -w);return this};e.build=function(a){if(!0===a)this._deferred_build=!0;else if(void 0===a||this._deferred_build)this._string=b.build(this._parts),this._deferred_build=!1;return this};e.clone=function(){return new b(this)};e.valueOf=e.toString=function(){return this.build(!1)._string};e.protocol=r("protocol");e.username=r("username");e.password=r("password");e.hostname=r("hostname");e.port=r("port");e.query=C("query","?");e.fragment=C("fragment","#");e.search=function(a,c){var b=this.query(a,c);return"string"=== -typeof b&&b.length?"?"+b:b};e.hash=function(a,c){var b=this.fragment(a,c);return"string"===typeof b&&b.length?"#"+b:b};e.pathname=function(a,c){if(void 0===a||!0===a){var d=this._parts.path||(this._parts.hostname?"/":"");return a?(this._parts.urn?b.decodeUrnPath:b.decodePath)(d):d}this._parts.path=this._parts.urn?a?b.recodeUrnPath(a):"":a?b.recodePath(a):"/";this.build(!c);return this};e.path=e.pathname;e.href=function(a,c){var d;if(void 0===a)return this.toString();this._string="";this._parts=b._parts(); -var l=a instanceof b,e="object"===typeof a&&(a.hostname||a.path||a.pathname);a.nodeName&&(e=b.getDomAttribute(a),a=a[e]||"",e=!1);!l&&e&&void 0!==a.pathname&&(a=a.toString());if("string"===typeof a||a instanceof String)this._parts=b.parse(String(a),this._parts);else if(l||e){l=l?a._parts:a;for(d in l)"query"!==d&&t.call(this._parts,d)&&(this._parts[d]=l[d]);l.query&&this.query(l.query,!1)}else throw new TypeError("invalid input");this.build(!c);return this};e.is=function(a){var c=!1,d=!1,e=!1,m=!1, -g=!1,f=!1,k=!1,p=!this._parts.urn;this._parts.hostname&&(p=!1,d=b.ip4_expression.test(this._parts.hostname),e=b.ip6_expression.test(this._parts.hostname),c=d||e,g=(m=!c)&&h&&h.has(this._parts.hostname),f=m&&b.idn_expression.test(this._parts.hostname),k=m&&b.punycode_expression.test(this._parts.hostname));switch(a.toLowerCase()){case "relative":return p;case "absolute":return!p;case "domain":case "name":return m;case "sld":return g;case "ip":return c;case "ip4":case "ipv4":case "inet4":return d;case "ip6":case "ipv6":case "inet6":return e; -case "idn":return f;case "url":return!this._parts.urn;case "urn":return!!this._parts.urn;case "punycode":return k}return null};var G=e.protocol,H=e.port,I=e.hostname;e.protocol=function(a,c){if(a&&(a=a.replace(/:(\/\/)?$/,""),!a.match(b.protocol_expression)))throw new TypeError('Protocol "'+a+"\" contains characters other than [A-Z0-9.+-] or doesn't start with [A-Z]");return G.call(this,a,c)};e.scheme=e.protocol;e.port=function(a,c){if(this._parts.urn)return void 0===a?"":this;void 0!==a&&(0===a&& -(a=null),a&&(a+="",":"===a.charAt(0)&&(a=a.substring(1)),b.ensureValidPort(a)));return H.call(this,a,c)};e.hostname=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0!==a){var d={preventInvalidHostname:this._parts.preventInvalidHostname};if("/"!==b.parseHost(a,d))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]');a=d.hostname;this._parts.preventInvalidHostname&&b.ensureValidHostname(a,this._parts.protocol)}return I.call(this,a,c)};e.origin=function(a, -c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){var d=this.protocol();return this.authority()?(d?d+"://":"")+this.authority():""}d=b(a);this.protocol(d.protocol()).authority(d.authority()).build(!c);return this};e.host=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a)return this._parts.hostname?b.buildHost(this._parts):"";if("/"!==b.parseHost(a,this._parts))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]');this.build(!c);return this}; -e.authority=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a)return this._parts.hostname?b.buildAuthority(this._parts):"";if("/"!==b.parseAuthority(a,this._parts))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]');this.build(!c);return this};e.userinfo=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){var d=b.buildUserinfo(this._parts);return d?d.substring(0,d.length-1):d}"@"!==a[a.length-1]&&(a+="@");b.parseUserinfo(a, -this._parts);this.build(!c);return this};e.resource=function(a,c){if(void 0===a)return this.path()+this.search()+this.hash();var d=b.parse(a);this._parts.path=d.path;this._parts.query=d.query;this._parts.fragment=d.fragment;this.build(!c);return this};e.subdomain=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var d=this._parts.hostname.length-this.domain().length-1;return this._parts.hostname.substring(0,d)||""}d=this._parts.hostname.length- -this.domain().length;d=this._parts.hostname.substring(0,d);d=new RegExp("^"+q(d));a&&"."!==a.charAt(a.length-1)&&(a+=".");if(-1!==a.indexOf(":"))throw new TypeError("Domains cannot contain colons");a&&b.ensureValidHostname(a,this._parts.protocol);this._parts.hostname=this._parts.hostname.replace(d,a);this.build(!c);return this};e.domain=function(a,c){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(c=a,a=void 0);if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var d= -this._parts.hostname.match(/\./g);if(d&&2>d.length)return this._parts.hostname;d=this._parts.hostname.length-this.tld(c).length-1;d=this._parts.hostname.lastIndexOf(".",d-1)+1;return this._parts.hostname.substring(d)||""}if(!a)throw new TypeError("cannot set domain empty");if(-1!==a.indexOf(":"))throw new TypeError("Domains cannot contain colons");b.ensureValidHostname(a,this._parts.protocol);!this._parts.hostname||this.is("IP")?this._parts.hostname=a:(d=new RegExp(q(this.domain())+"$"),this._parts.hostname= -this._parts.hostname.replace(d,a));this.build(!c);return this};e.tld=function(a,c){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(c=a,a=void 0);if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var b=this._parts.hostname.lastIndexOf(".");b=this._parts.hostname.substring(b+1);return!0!==c&&h&&h.list[b.toLowerCase()]?h.get(this._parts.hostname)||b:b}if(a)if(a.match(/[^a-zA-Z0-9-]/))if(h&&h.is(a))b=new RegExp(q(this.tld())+"$"),this._parts.hostname=this._parts.hostname.replace(b, -a);else throw new TypeError('TLD "'+a+'" contains characters other than [A-Z0-9]');else{if(!this._parts.hostname||this.is("IP"))throw new ReferenceError("cannot set TLD on non-domain host");b=new RegExp(q(this.tld())+"$");this._parts.hostname=this._parts.hostname.replace(b,a)}else throw new TypeError("cannot set TLD empty");this.build(!c);return this};e.directory=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path&&!this._parts.hostname)return""; -if("/"===this._parts.path)return"/";var d=this._parts.path.length-this.filename().length-1;d=this._parts.path.substring(0,d)||(this._parts.hostname?"/":"");return a?b.decodePath(d):d}d=this._parts.path.length-this.filename().length;d=this._parts.path.substring(0,d);d=new RegExp("^"+q(d));this.is("relative")||(a||(a="/"),"/"!==a.charAt(0)&&(a="/"+a));a&&"/"!==a.charAt(a.length-1)&&(a+="/");a=b.recodePath(a);this._parts.path=this._parts.path.replace(d,a);this.build(!c);return this};e.filename=function(a, -c){if(this._parts.urn)return void 0===a?"":this;if("string"!==typeof a){if(!this._parts.path||"/"===this._parts.path)return"";var d=this._parts.path.lastIndexOf("/");d=this._parts.path.substring(d+1);return a?b.decodePathSegment(d):d}d=!1;"/"===a.charAt(0)&&(a=a.substring(1));a.match(/\.?\//)&&(d=!0);var e=new RegExp(q(this.filename())+"$");a=b.recodePath(a);this._parts.path=this._parts.path.replace(e,a);d?this.normalizePath(c):this.build(!c);return this};e.suffix=function(a,c){if(this._parts.urn)return void 0=== -a?"":this;if(void 0===a||!0===a){if(!this._parts.path||"/"===this._parts.path)return"";var d=this.filename(),e=d.lastIndexOf(".");if(-1===e)return"";d=d.substring(e+1);d=/^[a-z0-9%]+$/i.test(d)?d:"";return a?b.decodePathSegment(d):d}"."===a.charAt(0)&&(a=a.substring(1));if(d=this.suffix())e=a?new RegExp(q(d)+"$"):new RegExp(q("."+d)+"$");else{if(!a)return this;this._parts.path+="."+b.recodePath(a)}e&&(a=b.recodePath(a),this._parts.path=this._parts.path.replace(e,a));this.build(!c);return this};e.segment= -function(a,c,b){var d=this._parts.urn?":":"/",e=this.path(),g="/"===e.substring(0,1);e=e.split(d);void 0!==a&&"number"!==typeof a&&(b=c,c=a,a=void 0);if(void 0!==a&&"number"!==typeof a)throw Error('Bad segment "'+a+'", must be 0-based integer');g&&e.shift();0>a&&(a=Math.max(e.length+a,0));if(void 0===c)return void 0===a?e:e[a];if(null===a||void 0===e[a])if(u(c)){e=[];a=0;for(var f=c.length;a=d||d>=p.length-1)return!1;var v=p.lastIndexOf(".",d-1);if(0>=v||v>=d-1)return!1;var E=k.list[p.slice(d+1)];return E?0<=E.indexOf(" "+p.slice(v+1,d)+" "):!1},is:function(p){var d=p.lastIndexOf(".");if(0>=d||d>=p.length-1||0<=p.lastIndexOf(".",d-1))return!1;var v=k.list[p.slice(d+1)];return v?0<=v.indexOf(" "+p.slice(0,d)+" "):!1},get:function(p){var d=p.lastIndexOf(".");if(0>=d||d>=p.length-1)return null;var v=p.lastIndexOf(".",d-1); +if(0>=v||v>=d-1)return null;var E=k.list[p.slice(d+1)];return!E||0>E.indexOf(" "+p.slice(v+1,d)+" ")?null:p.slice(v+1)},noConflict:function(){m.SecondLevelDomains===this&&(m.SecondLevelDomains=w);return this}};return k}); +(function(m,w){"object"===typeof module&&module.exports?module.exports=w(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"===typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],w):m.URI=w(m.punycode,m.IPv6,m.SecondLevelDomains,m)})(this,function(m,w,k,p){function d(a,b){var c=1<=arguments.length,e=2<=arguments.length;if(!(this instanceof d))return c?e?new d(a,b):new d(a):new d;if(void 0===a){if(c)throw new TypeError("undefined is not a valid argument for URI"); +a="undefined"!==typeof location?location.href+"":""}if(null===a&&c)throw new TypeError("null is not a valid argument for URI");this.href(a);return void 0!==b?this.absoluteTo(b):this}function v(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function E(a){return void 0===a?"Undefined":String(Object.prototype.toString.call(a)).slice(8,-1)}function A(a){return"Array"===E(a)}function l(a,b){var c={},e;if("RegExp"===E(b))c=null;else if(A(b)){var f=0;for(e=b.length;f]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u2018\u2019]))/ig;d.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u201e\u2018\u2019]+$/,parens:/(\([^\)]*\)|\[[^\]]*\]|\{[^}]*\}|<[^>]*>)/g};d.defaultPorts={http:"80",https:"443",ftp:"21", +gopher:"70",ws:"80",wss:"443"};d.hostProtocols=["http","https"];d.invalid_hostname_characters=/[^a-zA-Z0-9\.\-:_]/;d.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src",audio:"src",video:"src"};d.getDomAttribute=function(a){if(a&&a.nodeName){var b=a.nodeName.toLowerCase();if("input"!==b||"image"===a.type)return d.domAttributes[b]}};d.encode=u;d.decode=decodeURIComponent;d.iso8859= +function(){d.encode=escape;d.decode=unescape};d.unicode=function(){d.encode=u;d.decode=decodeURIComponent};d.characters={pathname:{encode:{expression:/%(24|26|2B|2C|3B|3D|3A|40)/ig,map:{"%24":"$","%26":"&","%2B":"+","%2C":",","%3B":";","%3D":"=","%3A":":","%40":"@"}},decode:{expression:/[\/\?#]/g,map:{"/":"%2F","?":"%3F","#":"%23"}}},reserved:{encode:{expression:/%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/ig,map:{"%3A":":","%2F":"/","%3F":"?","%23":"#","%5B":"[","%5D":"]","%40":"@", +"%21":"!","%24":"$","%26":"&","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"="}}},urnpath:{encode:{expression:/%(21|24|27|28|29|2A|2B|2C|3B|3D|40)/ig,map:{"%21":"!","%24":"$","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"=","%40":"@"}},decode:{expression:/[\/\?#:]/g,map:{"/":"%2F","?":"%3F","#":"%23",":":"%3A"}}}};d.encodeQuery=function(a,b){var c=d.encode(a+"");void 0===b&&(b=d.escapeQuerySpace);return b?c.replace(/%20/g,"+"):c};d.decodeQuery= +function(a,b){a+="";void 0===b&&(b=d.escapeQuerySpace);try{return d.decode(b?a.replace(/\+/g,"%20"):a)}catch(c){return a}};var I={encode:"encode",decode:"decode"},n,y=function(a,b){return function(c){try{return d[b](c+"").replace(d.characters[a][b].expression,function(e){return d.characters[a][b].map[e]})}catch(e){return c}}};for(n in I)d[n+"PathSegment"]=y("pathname",I[n]),d[n+"UrnPathSegment"]=y("urnpath",I[n]);I=function(a,b,c){return function(e){var f=c?function(J){return d[b](d[c](J))}:d[b]; +e=(e+"").split(a);for(var t=0,D=e.length;te)return a.charAt(0)===b.charAt(0)&&"/"===a.charAt(0)?"/":"";if("/"!==a.charAt(e)||"/"!==b.charAt(e))e=a.substring(0,e).lastIndexOf("/");return a.substring(0,e+1)};d.withinString=function(a,b,c){c||(c={});var e=c.start||d.findUri.start,f=c.end||d.findUri.end,t=c.trim||d.findUri.trim,D= +c.parens||d.findUri.parens,J=/[a-z0-9-]=["']?$/i;for(e.lastIndex=0;;){var L=e.exec(a);if(!L)break;var P=L.index;if(c.ignoreHtml){var N=a.slice(Math.max(P-3,0),P);if(N&&J.test(N))continue}var O=P+a.slice(P).search(f);N=a.slice(P,O);for(O=-1;;){var Q=D.exec(N);if(!Q)break;O=Math.max(O,Q.index+Q[0].length)}N=-1b))throw new TypeError('Port "'+a+'" is not a valid port');}};d.noConflict=function(a){if(a)return a={URI:this.noConflict()},p.URITemplate&&"function"===typeof p.URITemplate.noConflict&&(a.URITemplate=p.URITemplate.noConflict()),p.IPv6&&"function"===typeof p.IPv6.noConflict&&(a.IPv6=p.IPv6.noConflict()),p.SecondLevelDomains&&"function"===typeof p.SecondLevelDomains.noConflict&&(a.SecondLevelDomains=p.SecondLevelDomains.noConflict()), +a;p.URI===this&&(p.URI=z);return this};g.build=function(a){if(!0===a)this._deferred_build=!0;else if(void 0===a||this._deferred_build)this._string=d.build(this._parts),this._deferred_build=!1;return this};g.clone=function(){return new d(this)};g.valueOf=g.toString=function(){return this.build(!1)._string};g.protocol=x("protocol");g.username=x("username");g.password=x("password");g.hostname=x("hostname");g.port=x("port");g.query=B("query","?");g.fragment=B("fragment","#");g.search=function(a,b){var c= +this.query(a,b);return"string"===typeof c&&c.length?"?"+c:c};g.hash=function(a,b){var c=this.fragment(a,b);return"string"===typeof c&&c.length?"#"+c:c};g.pathname=function(a,b){if(void 0===a||!0===a){var c=this._parts.path||(this._parts.hostname?"/":"");return a?(this._parts.urn?d.decodeUrnPath:d.decodePath)(c):c}this._parts.path=this._parts.urn?a?d.recodeUrnPath(a):"":a?d.recodePath(a):"/";this.build(!b);return this};g.path=g.pathname;g.href=function(a,b){var c;if(void 0===a)return this.toString(); +this._string="";this._parts=d._parts();var e=a instanceof d,f="object"===typeof a&&(a.hostname||a.path||a.pathname);a.nodeName&&(f=d.getDomAttribute(a),a=a[f]||"",f=!1);!e&&f&&void 0!==a.pathname&&(a=a.toString());if("string"===typeof a||a instanceof String)this._parts=d.parse(String(a),this._parts);else if(e||f){e=e?a._parts:a;for(c in e)"query"!==c&&G.call(this._parts,c)&&(this._parts[c]=e[c]);e.query&&this.query(e.query,!1)}else throw new TypeError("invalid input");this.build(!b);return this}; +g.is=function(a){var b=!1,c=!1,e=!1,f=!1,t=!1,D=!1,J=!1,L=!this._parts.urn;this._parts.hostname&&(L=!1,c=d.ip4_expression.test(this._parts.hostname),e=d.ip6_expression.test(this._parts.hostname),b=c||e,t=(f=!b)&&k&&k.has(this._parts.hostname),D=f&&d.idn_expression.test(this._parts.hostname),J=f&&d.punycode_expression.test(this._parts.hostname));switch(a.toLowerCase()){case "relative":return L;case "absolute":return!L;case "domain":case "name":return f;case "sld":return t;case "ip":return b;case "ip4":case "ipv4":case "inet4":return c; +case "ip6":case "ipv6":case "inet6":return e;case "idn":return D;case "url":return!this._parts.urn;case "urn":return!!this._parts.urn;case "punycode":return J}return null};var H=g.protocol,C=g.port,K=g.hostname;g.protocol=function(a,b){if(a&&(a=a.replace(/:(\/\/)?$/,""),!a.match(d.protocol_expression)))throw new TypeError('Protocol "'+a+"\" contains characters other than [A-Z0-9.+-] or doesn't start with [A-Z]");return H.call(this,a,b)};g.scheme=g.protocol;g.port=function(a,b){if(this._parts.urn)return void 0=== +a?"":this;void 0!==a&&(0===a&&(a=null),a&&(a+="",":"===a.charAt(0)&&(a=a.substring(1)),d.ensureValidPort(a)));return C.call(this,a,b)};g.hostname=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0!==a){var c={preventInvalidHostname:this._parts.preventInvalidHostname};if("/"!==d.parseHost(a,c))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]');a=c.hostname;this._parts.preventInvalidHostname&&d.ensureValidHostname(a,this._parts.protocol)}return K.call(this, +a,b)};g.origin=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){var c=this.protocol();return this.authority()?(c?c+"://":"")+this.authority():""}c=d(a);this.protocol(c.protocol()).authority(c.authority()).build(!b);return this};g.host=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a)return this._parts.hostname?d.buildHost(this._parts):"";if("/"!==d.parseHost(a,this._parts))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]'); +this.build(!b);return this};g.authority=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a)return this._parts.hostname?d.buildAuthority(this._parts):"";if("/"!==d.parseAuthority(a,this._parts))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]');this.build(!b);return this};g.userinfo=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){var c=d.buildUserinfo(this._parts);return c?c.substring(0,c.length-1):c}"@"!==a[a.length-1]&& +(a+="@");d.parseUserinfo(a,this._parts);this.build(!b);return this};g.resource=function(a,b){if(void 0===a)return this.path()+this.search()+this.hash();var c=d.parse(a);this._parts.path=c.path;this._parts.query=c.query;this._parts.fragment=c.fragment;this.build(!b);return this};g.subdomain=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var c=this._parts.hostname.length-this.domain().length-1;return this._parts.hostname.substring(0, +c)||""}c=this._parts.hostname.length-this.domain().length;c=this._parts.hostname.substring(0,c);c=new RegExp("^"+v(c));a&&"."!==a.charAt(a.length-1)&&(a+=".");if(-1!==a.indexOf(":"))throw new TypeError("Domains cannot contain colons");a&&d.ensureValidHostname(a,this._parts.protocol);this._parts.hostname=this._parts.hostname.replace(c,a);this.build(!b);return this};g.domain=function(a,b){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(b=a,a=void 0);if(void 0===a){if(!this._parts.hostname|| +this.is("IP"))return"";var c=this._parts.hostname.match(/\./g);if(c&&2>c.length)return this._parts.hostname;c=this._parts.hostname.length-this.tld(b).length-1;c=this._parts.hostname.lastIndexOf(".",c-1)+1;return this._parts.hostname.substring(c)||""}if(!a)throw new TypeError("cannot set domain empty");if(-1!==a.indexOf(":"))throw new TypeError("Domains cannot contain colons");d.ensureValidHostname(a,this._parts.protocol);!this._parts.hostname||this.is("IP")?this._parts.hostname=a:(c=new RegExp(v(this.domain())+ +"$"),this._parts.hostname=this._parts.hostname.replace(c,a));this.build(!b);return this};g.tld=function(a,b){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(b=a,a=void 0);if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var c=this._parts.hostname.lastIndexOf(".");c=this._parts.hostname.substring(c+1);return!0!==b&&k&&k.list[c.toLowerCase()]?k.get(this._parts.hostname)||c:c}if(a)if(a.match(/[^a-zA-Z0-9-]/))if(k&&k.is(a))c=new RegExp(v(this.tld())+"$"),this._parts.hostname= +this._parts.hostname.replace(c,a);else throw new TypeError('TLD "'+a+'" contains characters other than [A-Z0-9]');else{if(!this._parts.hostname||this.is("IP"))throw new ReferenceError("cannot set TLD on non-domain host");c=new RegExp(v(this.tld())+"$");this._parts.hostname=this._parts.hostname.replace(c,a)}else throw new TypeError("cannot set TLD empty");this.build(!b);return this};g.directory=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path&& +!this._parts.hostname)return"";if("/"===this._parts.path)return"/";var c=this._parts.path.length-this.filename().length-1;c=this._parts.path.substring(0,c)||(this._parts.hostname?"/":"");return a?d.decodePath(c):c}c=this._parts.path.length-this.filename().length;c=this._parts.path.substring(0,c);c=new RegExp("^"+v(c));this.is("relative")||(a||(a="/"),"/"!==a.charAt(0)&&(a="/"+a));a&&"/"!==a.charAt(a.length-1)&&(a+="/");a=d.recodePath(a);this._parts.path=this._parts.path.replace(c,a);this.build(!b); +return this};g.filename=function(a,b){if(this._parts.urn)return void 0===a?"":this;if("string"!==typeof a){if(!this._parts.path||"/"===this._parts.path)return"";var c=this._parts.path.lastIndexOf("/");c=this._parts.path.substring(c+1);return a?d.decodePathSegment(c):c}c=!1;"/"===a.charAt(0)&&(a=a.substring(1));a.match(/\.?\//)&&(c=!0);var e=new RegExp(v(this.filename())+"$");a=d.recodePath(a);this._parts.path=this._parts.path.replace(e,a);c?this.normalizePath(b):this.build(!b);return this};g.suffix= +function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path||"/"===this._parts.path)return"";var c=this.filename(),e=c.lastIndexOf(".");if(-1===e)return"";c=c.substring(e+1);c=/^[a-z0-9%]+$/i.test(c)?c:"";return a?d.decodePathSegment(c):c}"."===a.charAt(0)&&(a=a.substring(1));if(c=this.suffix())e=a?new RegExp(v(c)+"$"):new RegExp(v("."+c)+"$");else{if(!a)return this;this._parts.path+="."+d.recodePath(a)}e&&(a=d.recodePath(a),this._parts.path=this._parts.path.replace(e, +a));this.build(!b);return this};g.segment=function(a,b,c){var e=this._parts.urn?":":"/",f=this.path(),t="/"===f.substring(0,1);f=f.split(e);void 0!==a&&"number"!==typeof a&&(c=b,b=a,a=void 0);if(void 0!==a&&"number"!==typeof a)throw Error('Bad segment "'+a+'", must be 0-based integer');t&&f.shift();0>a&&(a=Math.max(f.length+a,0));if(void 0===b)return void 0===a?f:f[a];if(null===a||void 0===f[a])if(A(b)){f=[];a=0;for(var D=b.length;a{}"`^| \\]/;h.expand=function(b,f,k){var g=u[b.operator],p=g.named?"Named":"Unnamed";b=b.variables;var n=[],r,q;for(q=0;r=b[q];q++){var w=f.get(r.name);if(0===w.type&&k&&k.strict)throw Error('Missing expansion value for variable "'+ -r.name+'"');if(w.val.length){if(1{}"`^| \\]/;k.expand=function(l,r,F){var h=A[l.operator],q=h.named?"Named":"Unnamed";l=l.variables;var u=[],x,B;for(B=0;x=l[B];B++){var z=r.get(x.name);if(0===z.type&&F&&F.strict)throw Error('Missing expansion value for variable "'+ +x.name+'"');if(z.val.length){if(1 Date: Wed, 23 Dec 2020 10:46:27 -0500 Subject: [PATCH 42/44] fix(parse): treat backslash as forwardslash in authority (#403) make `https://attacker.com\\@example.com` like `https://attacker.com\\@example.com/` result in `https://attacker.com/@example.com` --- src/URI.js | 9 ++++++--- test/urls.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/src/URI.js b/src/URI.js index 715c097e..92c04811 100644 --- a/src/URI.js +++ b/src/URI.js @@ -612,19 +612,22 @@ }; URI.parseUserinfo = function(string, parts) { // extract username:password + var _string = string var firstBackSlash = string.indexOf('\\'); + if (firstBackSlash !== -1) { + string = string.replace(/\\/g, '/') + } var firstSlash = string.indexOf('/'); - var slash = firstBackSlash === -1 ? firstSlash : (firstSlash !== -1 ? Math.min(firstBackSlash, firstSlash): firstSlash) var pos = string.lastIndexOf('@', firstSlash > -1 ? firstSlash : string.length - 1); var t; // authority@ must come before /path or \path - if (pos > -1 && (slash === -1 || pos < slash)) { + if (pos > -1 && (firstSlash === -1 || pos < firstSlash)) { t = string.substring(0, pos).split(':'); parts.username = t[0] ? URI.decode(t[0]) : null; t.shift(); parts.password = t[0] ? URI.decode(t.join(':')) : null; - string = string.substring(pos + 1); + string = _string.substring(pos + 1); } else { parts.username = null; parts.password = null; diff --git a/test/urls.js b/test/urls.js index 5e0c06eb..14255c16 100644 --- a/test/urls.js +++ b/test/urls.js @@ -2033,6 +2033,55 @@ var urls = [{ idn: false, punycode: false } + }, { + name: 'backslashes authority, no ending slash', + url: 'https://attacker.com\\@example.com', + _url: 'https://attacker.com/@example.com', + parts: { + protocol: 'https', + username: null, + password: null, + hostname: 'attacker.com', + port: null, + path: '/@example.com', + query: null, + fragment: null + }, + accessors: { + protocol: 'https', + username: '', + password: '', + port: '', + path: '/@example.com', + query: '', + fragment: '', + resource: '/@example.com', + authority: 'attacker.com', + origin: 'https://attacker.com', + userinfo: '', + subdomain: '', + domain: 'attacker.com', + tld: 'com', + directory: '/', + filename: '@example.com', + suffix: 'com', + hash: '', + search: '', + host: 'attacker.com', + hostname: 'attacker.com' + }, + is: { + urn: false, + url: true, + relative: false, + name: true, + sld: false, + ip: false, + ip4: false, + ip6: false, + idn: false, + punycode: false + } } ]; From bf04ec5f053829f9ea3a887608bdfca4fd84cd64 Mon Sep 17 00:00:00 2001 From: Rodney Rehm Date: Wed, 23 Dec 2020 16:55:07 +0100 Subject: [PATCH 43/44] chore(build): bumping to version 1.19.4 --- CHANGELOG.md | 7 ++++++- bower.json | 2 +- build.js | 2 +- package.json | 2 +- src/IPv6.js | 2 +- src/SecondLevelDomains.js | 2 +- src/URI.js | 4 ++-- src/URI.min.js | 6 +++--- src/URITemplate.js | 2 +- src/jquery.URI.js | 2 +- src/jquery.URI.min.js | 2 +- 11 files changed, 19 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0319e94..202340d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,14 @@ The release notes tracked in this document are also made available on the [releases page](https://github.com/medialize/URI.js/releases) +### 1.19.4 (December 23rd 2020) ### + +* **SECURITY** fixing [`URI.parseAuthority()`](http://medialize.github.io/URI.js/docs.html#static-parseAuthority) to rewrite `\` to `/` as Node and Browsers do - followed up to by [alesandroortiz](https://github.com/alesandroortiz) in [PR #403](https://github.com/medialize/URI.js/issues/403), relates to [Issue #233](https://github.com/medialize/URI.js/pull/233) + ### 1.19.3 (December 20th 2020) ### -* **SECURITY** fixing [`URI.parseAuthority()`](http://medialize.github.io/URI.js/docs.html#static-parseAuthority) to rewrite `\` to `/` as Node and Browsers do - disclosed privately, relates to [Issue #233](https://github.com/medialize/URI.js/pull/233) +* **SECURITY** fixing [`URI.parseAuthority()`](http://medialize.github.io/URI.js/docs.html#static-parseAuthority) to rewrite `\` to `/` as Node and Browsers do - disclosed privately by [alesandroortiz](https://github.com/alesandroortiz), relates to [Issue #233](https://github.com/medialize/URI.js/pull/233) + ### 1.19.2 (October 20th 2019) ### * fixing [`URI.build()`](http://medialize.github.io/URI.js/docs.html#static-build) to properly handle relative paths when a scheme is given - [Issue #387](https://github.com/medialize/URI.js/issues/387) diff --git a/bower.json b/bower.json index e9da2366..f348d96e 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "urijs", - "version": "1.19.3", + "version": "1.19.4", "main": "src/URI.js", "ignore": [ ".*", diff --git a/build.js b/build.js index f25e6286..81424f35 100644 --- a/build.js +++ b/build.js @@ -29,7 +29,7 @@ function build(files) { output_format: "text", output_info: "compiled_code" }, function(data) { - var code = "/*! URI.js v1.19.3 http://medialize.github.io/URI.js/ */\n/* build contains: " + files.join(', ') + " */\n" + data; + var code = "/*! URI.js v1.19.4 http://medialize.github.io/URI.js/ */\n/* build contains: " + files.join(', ') + " */\n" + data; $progress.hide(); $out.val(code).parent().show(); $out.prev().find('a').remove(); diff --git a/package.json b/package.json index f25b0067..40c4529d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "urijs", - "version": "1.19.3", + "version": "1.19.4", "title": "URI.js - Mutating URLs", "author": { "name": "Rodney Rehm", diff --git a/src/IPv6.js b/src/IPv6.js index 80931d5a..01020b0d 100644 --- a/src/IPv6.js +++ b/src/IPv6.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * IPv6 Support * - * Version: 1.19.3 + * Version: 1.19.4 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/SecondLevelDomains.js b/src/SecondLevelDomains.js index 648b5087..c0e9606d 100644 --- a/src/SecondLevelDomains.js +++ b/src/SecondLevelDomains.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * Second Level Domain (SLD) Support * - * Version: 1.19.3 + * Version: 1.19.4 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/URI.js b/src/URI.js index 92c04811..e1632d09 100644 --- a/src/URI.js +++ b/src/URI.js @@ -1,7 +1,7 @@ /*! * URI.js - Mutating URLs * - * Version: 1.19.3 + * Version: 1.19.4 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ @@ -81,7 +81,7 @@ return /^[0-9]+$/.test(value); } - URI.version = '1.19.3'; + URI.version = '1.19.4'; var p = URI.prototype; var hasOwn = Object.prototype.hasOwnProperty; diff --git a/src/URI.min.js b/src/URI.min.js index d515ae5e..e2c46b32 100644 --- a/src/URI.min.js +++ b/src/URI.min.js @@ -1,4 +1,4 @@ -/*! URI.js v1.19.3 http://medialize.github.io/URI.js/ */ +/*! URI.js v1.19.4 http://medialize.github.io/URI.js/ */ /* build contains: IPv6.js, punycode.js, SecondLevelDomains.js, URI.js, URITemplate.js, jquery.URI.js */ (function(m,w){"object"===typeof module&&module.exports?module.exports=w():"function"===typeof define&&define.amd?define(w):m.IPv6=w(m)})(this,function(m){var w=m&&m.IPv6;return{best:function(k){k=k.toLowerCase().split(":");var p=k.length,d=8;""===k[0]&&""===k[1]&&""===k[2]?(k.shift(),k.shift()):""===k[0]&&""===k[1]?k.shift():""===k[p-1]&&""===k[p-2]&&k.pop();p=k.length;-1!==k[p-1].indexOf(".")&&(d=7);var v;for(v=0;vE;E++)if("0"===p[0]&&1E&&(p=l,E=A)):"0"===k[v]&&(r=!0,l=v,A=1);A>E&&(p=l,E=A);1=v||v>=d-1)return null;var E=k.list[p.slice(d+1)];return!E||0>E.indexOf(" " (function(m,w){"object"===typeof module&&module.exports?module.exports=w(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"===typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],w):m.URI=w(m.punycode,m.IPv6,m.SecondLevelDomains,m)})(this,function(m,w,k,p){function d(a,b){var c=1<=arguments.length,e=2<=arguments.length;if(!(this instanceof d))return c?e?new d(a,b):new d(a):new d;if(void 0===a){if(c)throw new TypeError("undefined is not a valid argument for URI"); a="undefined"!==typeof location?location.href+"":""}if(null===a&&c)throw new TypeError("null is not a valid argument for URI");this.href(a);return void 0!==b?this.absoluteTo(b):this}function v(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function E(a){return void 0===a?"Undefined":String(Object.prototype.toString.call(a)).slice(8,-1)}function A(a){return"Array"===E(a)}function l(a,b){var c={},e;if("RegExp"===E(b))c=null;else if(A(b)){var f=0;for(e=b.length;f]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u2018\u2019]))/ig;d.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u201e\u2018\u2019]+$/,parens:/(\([^\)]*\)|\[[^\]]*\]|\{[^}]*\}|<[^>]*>)/g};d.defaultPorts={http:"80",https:"443",ftp:"21", @@ -37,7 +37,7 @@ function(a,b){a+="";void 0===b&&(b=d.escapeQuerySpace);try{return d.decode(b?a.r e=(e+"").split(a);for(var t=0,D=e.length;t Date: Wed, 30 Dec 2020 21:48:25 +0100 Subject: [PATCH 44/44] chore(build): bumping to version 1.19.5 --- CHANGELOG.md | 4 ++ bower.json | 2 +- build.js | 2 +- package.json | 2 +- src/IPv6.js | 2 +- src/SecondLevelDomains.js | 2 +- src/URI.js | 4 +- src/URI.min.js | 129 ++++++++++++++++++-------------------- src/URITemplate.js | 2 +- src/jquery.URI.js | 2 +- src/jquery.URI.min.js | 12 ++-- 11 files changed, 81 insertions(+), 82 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 202340d4..9b5355b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ The release notes tracked in this document are also made available on the [releases page](https://github.com/medialize/URI.js/releases) +### 1.19.5 (December 30th 2020) ### + +* dropping jquery.URI.js from minified bundle accidentally added since v1.19.3 - [Issue #404](https://github.com/medialize/URI.js/issues/404) + ### 1.19.4 (December 23rd 2020) ### * **SECURITY** fixing [`URI.parseAuthority()`](http://medialize.github.io/URI.js/docs.html#static-parseAuthority) to rewrite `\` to `/` as Node and Browsers do - followed up to by [alesandroortiz](https://github.com/alesandroortiz) in [PR #403](https://github.com/medialize/URI.js/issues/403), relates to [Issue #233](https://github.com/medialize/URI.js/pull/233) diff --git a/bower.json b/bower.json index f348d96e..f7d7a13b 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "urijs", - "version": "1.19.4", + "version": "1.19.5", "main": "src/URI.js", "ignore": [ ".*", diff --git a/build.js b/build.js index 81424f35..f16736ad 100644 --- a/build.js +++ b/build.js @@ -29,7 +29,7 @@ function build(files) { output_format: "text", output_info: "compiled_code" }, function(data) { - var code = "/*! URI.js v1.19.4 http://medialize.github.io/URI.js/ */\n/* build contains: " + files.join(', ') + " */\n" + data; + var code = "/*! URI.js v1.19.5 http://medialize.github.io/URI.js/ */\n/* build contains: " + files.join(', ') + " */\n" + data; $progress.hide(); $out.val(code).parent().show(); $out.prev().find('a').remove(); diff --git a/package.json b/package.json index 40c4529d..dd71db7c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "urijs", - "version": "1.19.4", + "version": "1.19.5", "title": "URI.js - Mutating URLs", "author": { "name": "Rodney Rehm", diff --git a/src/IPv6.js b/src/IPv6.js index 01020b0d..26f84d1a 100644 --- a/src/IPv6.js +++ b/src/IPv6.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * IPv6 Support * - * Version: 1.19.4 + * Version: 1.19.5 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/SecondLevelDomains.js b/src/SecondLevelDomains.js index c0e9606d..125d1c5a 100644 --- a/src/SecondLevelDomains.js +++ b/src/SecondLevelDomains.js @@ -2,7 +2,7 @@ * URI.js - Mutating URLs * Second Level Domain (SLD) Support * - * Version: 1.19.4 + * Version: 1.19.5 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ diff --git a/src/URI.js b/src/URI.js index e1632d09..757507d5 100644 --- a/src/URI.js +++ b/src/URI.js @@ -1,7 +1,7 @@ /*! * URI.js - Mutating URLs * - * Version: 1.19.4 + * Version: 1.19.5 * * Author: Rodney Rehm * Web: http://medialize.github.io/URI.js/ @@ -81,7 +81,7 @@ return /^[0-9]+$/.test(value); } - URI.version = '1.19.4'; + URI.version = '1.19.5'; var p = URI.prototype; var hasOwn = Object.prototype.hasOwnProperty; diff --git a/src/URI.min.js b/src/URI.min.js index e2c46b32..452fa68f 100644 --- a/src/URI.min.js +++ b/src/URI.min.js @@ -1,14 +1,14 @@ -/*! URI.js v1.19.4 http://medialize.github.io/URI.js/ */ -/* build contains: IPv6.js, punycode.js, SecondLevelDomains.js, URI.js, URITemplate.js, jquery.URI.js */ -(function(m,w){"object"===typeof module&&module.exports?module.exports=w():"function"===typeof define&&define.amd?define(w):m.IPv6=w(m)})(this,function(m){var w=m&&m.IPv6;return{best:function(k){k=k.toLowerCase().split(":");var p=k.length,d=8;""===k[0]&&""===k[1]&&""===k[2]?(k.shift(),k.shift()):""===k[0]&&""===k[1]?k.shift():""===k[p-1]&&""===k[p-2]&&k.pop();p=k.length;-1!==k[p-1].indexOf(".")&&(d=7);var v;for(v=0;vE;E++)if("0"===p[0]&&1E&&(p=l,E=A)):"0"===k[v]&&(r=!0,l=v,A=1);A>E&&(p=l,E=A);1=K&&H>>10&1023|55296),y=56320|y&1023);return H+=g(y)}).join("")}function E(n,y,H){var C=0;n=H?z(n/700):n>>1;for(n+=z(n/y);455c&&(c=0);for(a=0;a=H&&w("invalid-input");var f=n.charCodeAt(c++);f=10>f-48?f-22:26>f-65?f-65:26>f-97?f-97:36; -(36<=f||f>z((2147483647-C)/e))&&w("overflow");C+=f*e;var t=b<=M?1:b>=M+26?26:b-M;if(fz(2147483647/f)&&w("overflow");e*=f}e=y.length+1;M=E(C-a,e,0==a);z(C/e)>2147483647-K&&w("overflow");K+=z(C/e);C%=e;y.splice(C++,0,K)}return v(y)}function l(n){var y,H,C,K=[];n=d(n);var M=n.length;var a=128;var b=0;var c=72;for(C=0;Ce&&K.push(g(e))}for((y=H=K.length)&&K.push("-");y=a&&ez((2147483647-b)/t)&& -w("overflow");b+=(f-a)*t;a=f;for(C=0;C=c+26?26:f-c;if(De)-0));D=z(J/D)}K.push(g(D+22+75*(26>D)-0));c=E(b,t,y==H);b=0;++y}++b;++a}return K.join("")}var r="object"==typeof exports&&exports&&!exports.nodeType&&exports,F="object"==typeof module&&module&&!module.nodeType&&module,h="object"==typeof global&&global;if(h.global===h||h.window===h|| -h.self===h)m=h;var q=/^xn--/,u=/[^\x20-\x7E]/,x=/[\x2E\u3002\uFF0E\uFF61]/g,B={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},z=Math.floor,g=String.fromCharCode,G;var I={version:"1.3.2",ucs2:{decode:d,encode:v},decode:A,encode:l,toASCII:function(n){return p(n,function(y){return u.test(y)?"xn--"+l(y):y})},toUnicode:function(n){return p(n,function(y){return q.test(y)?A(y.slice(4).toLowerCase()): -y})}};if("function"==typeof define&&"object"==typeof define.amd&&define.amd)define("punycode",function(){return I});else if(r&&F)if(module.exports==r)F.exports=I;else for(G in I)I.hasOwnProperty(G)&&(r[G]=I[G]);else m.punycode=I})(this); -(function(m,w){"object"===typeof module&&module.exports?module.exports=w():"function"===typeof define&&define.amd?define(w):m.SecondLevelDomains=w(m)})(this,function(m){var w=m&&m.SecondLevelDomains,k={list:{ac:" com gov mil net org ",ae:" ac co gov mil name net org pro sch ",af:" com edu gov net org ",al:" com edu gov mil net org ",ao:" co ed gv it og pb ",ar:" com edu gob gov int mil net org tur ",at:" ac co gv or ",au:" asn com csiro edu gov id net org ",ba:" co com edu gov mil net org rs unbi unmo unsa untz unze ", +/*! URI.js v1.19.5 http://medialize.github.io/URI.js/ */ +/* build contains: IPv6.js, punycode.js, SecondLevelDomains.js, URI.js, URITemplate.js */ +(function(r,x){"object"===typeof module&&module.exports?module.exports=x():"function"===typeof define&&define.amd?define(x):r.IPv6=x(r)})(this,function(r){var x=r&&r.IPv6;return{best:function(k){k=k.toLowerCase().split(":");var m=k.length,d=8;""===k[0]&&""===k[1]&&""===k[2]?(k.shift(),k.shift()):""===k[0]&&""===k[1]?k.shift():""===k[m-1]&&""===k[m-2]&&k.pop();m=k.length;-1!==k[m-1].indexOf(".")&&(d=7);var q;for(q=0;qE;E++)if("0"===m[0]&&1E&&(m=h,E=A)):"0"===k[q]&&(p=!0,h=q,A=1);A>E&&(m=h,E=A);1=J&&C>>10&1023|55296),t=56320|t&1023);return C+=g(t)}).join("")}function E(l,t,C){var y=0;l=C?v(l/700):l>>1;for(l+=v(l/t);455c&&(c=0);for(a=0;a=C&&x("invalid-input");var f=l.charCodeAt(c++);f=10>f-48?f-22:26>f-65?f-65:26>f-97?f-97:36; +(36<=f||f>v((2147483647-y)/e))&&x("overflow");y+=f*e;var n=b<=M?1:b>=M+26?26:b-M;if(fv(2147483647/f)&&x("overflow");e*=f}e=t.length+1;M=E(y-a,e,0==a);v(y/e)>2147483647-J&&x("overflow");J+=v(y/e);y%=e;t.splice(y++,0,J)}return q(t)}function h(l){var t,C,y,J=[];l=d(l);var M=l.length;var a=128;var b=0;var c=72;for(y=0;ye&&J.push(g(e))}for((t=C=J.length)&&J.push("-");t=a&&ev((2147483647-b)/n)&& +x("overflow");b+=(f-a)*n;a=f;for(y=0;y=c+26?26:f-c;if(ze)-0));z=v(I/z)}J.push(g(z+22+75*(26>z)-0));c=E(b,n,t==C);b=0;++t}++b;++a}return J.join("")}var p="object"==typeof exports&&exports&&!exports.nodeType&&exports,D="object"==typeof module&&module&&!module.nodeType&&module,u="object"==typeof global&&global;if(u.global===u||u.window===u|| +u.self===u)r=u;var K=/^xn--/,F=/[^\x20-\x7E]/,w=/[\x2E\u3002\uFF0E\uFF61]/g,H={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},v=Math.floor,g=String.fromCharCode,B;var G={version:"1.3.2",ucs2:{decode:d,encode:q},decode:A,encode:h,toASCII:function(l){return m(l,function(t){return F.test(t)?"xn--"+h(t):t})},toUnicode:function(l){return m(l,function(t){return K.test(t)?A(t.slice(4).toLowerCase()): +t})}};if("function"==typeof define&&"object"==typeof define.amd&&define.amd)define("punycode",function(){return G});else if(p&&D)if(module.exports==p)D.exports=G;else for(B in G)G.hasOwnProperty(B)&&(p[B]=G[B]);else r.punycode=G})(this); +(function(r,x){"object"===typeof module&&module.exports?module.exports=x():"function"===typeof define&&define.amd?define(x):r.SecondLevelDomains=x(r)})(this,function(r){var x=r&&r.SecondLevelDomains,k={list:{ac:" com gov mil net org ",ae:" ac co gov mil name net org pro sch ",af:" com edu gov net org ",al:" com edu gov mil net org ",ao:" co ed gv it og pb ",ar:" com edu gob gov int mil net org tur ",at:" ac co gv or ",au:" asn com csiro edu gov id net org ",ba:" co com edu gov mil net org rs unbi unmo unsa untz unze ", bb:" biz co com edu gov info net org store tv ",bh:" biz cc com edu gov info net org ",bn:" com edu gov net org ",bo:" com edu gob gov int mil net org tv ",br:" adm adv agr am arq art ato b bio blog bmd cim cng cnt com coop ecn edu eng esp etc eti far flog fm fnd fot fst g12 ggf gov imb ind inf jor jus lel mat med mil mus net nom not ntr odo org ppg pro psc psi qsl rec slg srv tmp trd tur tv vet vlog wiki zlg ",bs:" com edu gov net org ",bz:" du et om ov rg ",ca:" ab bc mb nb nf nl ns nt nu on pe qc sk yk ", ck:" biz co edu gen gov info net org ",cn:" ac ah bj com cq edu fj gd gov gs gx gz ha hb he hi hl hn jl js jx ln mil net nm nx org qh sc sd sh sn sx tj tw xj xz yn zj ",co:" com edu gov mil net nom org ",cr:" ac c co ed fi go or sa ",cy:" ac biz com ekloges gov ltd name net org parliament press pro tm ","do":" art com edu gob gov mil net org sld web ",dz:" art asso com edu gov net org pol ",ec:" com edu fin gov info med mil net org pro ",eg:" com edu eun gov mil name net org sci ",er:" com edu gov ind mil net org rochest w ", es:" com edu gob nom org ",et:" biz com edu gov info name net org ",fj:" ac biz com info mil name net org pro ",fk:" ac co gov net nom org ",fr:" asso com f gouv nom prd presse tm ",gg:" co net org ",gh:" com edu gov mil org ",gn:" ac com gov net org ",gr:" com edu gov mil net org ",gt:" com edu gob ind mil net org ",gu:" com edu gov net org ",hk:" com edu gov idv net org ",hu:" 2000 agrar bolt casino city co erotica erotika film forum games hotel info ingatlan jogasz konyvelo lakas media news org priv reklam sex shop sport suli szex tm tozsde utazas video ", @@ -21,78 +21,73 @@ tw:" club com ebiz edu game gov idv mil net org ",mu:" ac co com gov net or org rw:" ac co com edu gouv gov int mil net ",sa:" com edu gov med net org pub sch ",sd:" com edu gov info med net org tv ",se:" a ac b bd c d e f g h i k l m n o org p parti pp press r s t tm u w x y z ",sg:" com edu gov idn net org per ",sn:" art com edu gouv org perso univ ",sy:" com edu gov mil net news org ",th:" ac co go in mi net or ",tj:" ac biz co com edu go gov info int mil name net nic org test web ",tn:" agrinet com defense edunet ens fin gov ind info intl mincom nat net org perso rnrt rns rnu tourism ", tz:" ac co go ne or ",ua:" biz cherkassy chernigov chernovtsy ck cn co com crimea cv dn dnepropetrovsk donetsk dp edu gov if in ivano-frankivsk kh kharkov kherson khmelnitskiy kiev kirovograd km kr ks kv lg lugansk lutsk lviv me mk net nikolaev od odessa org pl poltava pp rovno rv sebastopol sumy te ternopil uzhgorod vinnica vn zaporizhzhe zhitomir zp zt ",ug:" ac co go ne or org sc ",uk:" ac bl british-library co cym gov govt icnet jet lea ltd me mil mod national-library-scotland nel net nhs nic nls org orgn parliament plc police sch scot soc ", us:" dni fed isa kids nsn ",uy:" com edu gub mil net org ",ve:" co com edu gob info mil net org web ",vi:" co com k12 net org ",vn:" ac biz com edu gov health info int name net org pro ",ye:" co com gov ltd me net org plc ",yu:" ac co edu gov org ",za:" ac agric alt bourse city co cybernet db edu gov grondar iaccess imt inca landesign law mil net ngo nis nom olivetti org pix school tm web ",zm:" ac co com edu gov net org sch ",com:"ar br cn de eu gb gr hu jpn kr no qc ru sa se uk us uy za ",net:"gb jp se uk ", -org:"ae",de:"com "},has:function(p){var d=p.lastIndexOf(".");if(0>=d||d>=p.length-1)return!1;var v=p.lastIndexOf(".",d-1);if(0>=v||v>=d-1)return!1;var E=k.list[p.slice(d+1)];return E?0<=E.indexOf(" "+p.slice(v+1,d)+" "):!1},is:function(p){var d=p.lastIndexOf(".");if(0>=d||d>=p.length-1||0<=p.lastIndexOf(".",d-1))return!1;var v=k.list[p.slice(d+1)];return v?0<=v.indexOf(" "+p.slice(0,d)+" "):!1},get:function(p){var d=p.lastIndexOf(".");if(0>=d||d>=p.length-1)return null;var v=p.lastIndexOf(".",d-1); -if(0>=v||v>=d-1)return null;var E=k.list[p.slice(d+1)];return!E||0>E.indexOf(" "+p.slice(v+1,d)+" ")?null:p.slice(v+1)},noConflict:function(){m.SecondLevelDomains===this&&(m.SecondLevelDomains=w);return this}};return k}); -(function(m,w){"object"===typeof module&&module.exports?module.exports=w(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"===typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],w):m.URI=w(m.punycode,m.IPv6,m.SecondLevelDomains,m)})(this,function(m,w,k,p){function d(a,b){var c=1<=arguments.length,e=2<=arguments.length;if(!(this instanceof d))return c?e?new d(a,b):new d(a):new d;if(void 0===a){if(c)throw new TypeError("undefined is not a valid argument for URI"); -a="undefined"!==typeof location?location.href+"":""}if(null===a&&c)throw new TypeError("null is not a valid argument for URI");this.href(a);return void 0!==b?this.absoluteTo(b):this}function v(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function E(a){return void 0===a?"Undefined":String(Object.prototype.toString.call(a)).slice(8,-1)}function A(a){return"Array"===E(a)}function l(a,b){var c={},e;if("RegExp"===E(b))c=null;else if(A(b)){var f=0;for(e=b.length;f=d||d>=m.length-1)return!1;var q=m.lastIndexOf(".",d-1);if(0>=q||q>=d-1)return!1;var E=k.list[m.slice(d+1)];return E?0<=E.indexOf(" "+m.slice(q+1,d)+" "):!1},is:function(m){var d=m.lastIndexOf(".");if(0>=d||d>=m.length-1||0<=m.lastIndexOf(".",d-1))return!1;var q=k.list[m.slice(d+1)];return q?0<=q.indexOf(" "+m.slice(0,d)+" "):!1},get:function(m){var d=m.lastIndexOf(".");if(0>=d||d>=m.length-1)return null;var q=m.lastIndexOf(".",d-1); +if(0>=q||q>=d-1)return null;var E=k.list[m.slice(d+1)];return!E||0>E.indexOf(" "+m.slice(q+1,d)+" ")?null:m.slice(q+1)},noConflict:function(){r.SecondLevelDomains===this&&(r.SecondLevelDomains=x);return this}};return k}); +(function(r,x){"object"===typeof module&&module.exports?module.exports=x(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"===typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],x):r.URI=x(r.punycode,r.IPv6,r.SecondLevelDomains,r)})(this,function(r,x,k,m){function d(a,b){var c=1<=arguments.length,e=2<=arguments.length;if(!(this instanceof d))return c?e?new d(a,b):new d(a):new d;if(void 0===a){if(c)throw new TypeError("undefined is not a valid argument for URI"); +a="undefined"!==typeof location?location.href+"":""}if(null===a&&c)throw new TypeError("null is not a valid argument for URI");this.href(a);return void 0!==b?this.absoluteTo(b):this}function q(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function E(a){return void 0===a?"Undefined":String(Object.prototype.toString.call(a)).slice(8,-1)}function A(a){return"Array"===E(a)}function h(a,b){var c={},e;if("RegExp"===E(b))c=null;else if(A(b)){var f=0;for(e=b.length;f]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u2018\u2019]))/ig;d.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u201e\u2018\u2019]+$/,parens:/(\([^\)]*\)|\[[^\]]*\]|\{[^}]*\}|<[^>]*>)/g};d.defaultPorts={http:"80",https:"443",ftp:"21", -gopher:"70",ws:"80",wss:"443"};d.hostProtocols=["http","https"];d.invalid_hostname_characters=/[^a-zA-Z0-9\.\-:_]/;d.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src",audio:"src",video:"src"};d.getDomAttribute=function(a){if(a&&a.nodeName){var b=a.nodeName.toLowerCase();if("input"!==b||"image"===a.type)return d.domAttributes[b]}};d.encode=u;d.decode=decodeURIComponent;d.iso8859= -function(){d.encode=escape;d.decode=unescape};d.unicode=function(){d.encode=u;d.decode=decodeURIComponent};d.characters={pathname:{encode:{expression:/%(24|26|2B|2C|3B|3D|3A|40)/ig,map:{"%24":"$","%26":"&","%2B":"+","%2C":",","%3B":";","%3D":"=","%3A":":","%40":"@"}},decode:{expression:/[\/\?#]/g,map:{"/":"%2F","?":"%3F","#":"%23"}}},reserved:{encode:{expression:/%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/ig,map:{"%3A":":","%2F":"/","%3F":"?","%23":"#","%5B":"[","%5D":"]","%40":"@", +gopher:"70",ws:"80",wss:"443"};d.hostProtocols=["http","https"];d.invalid_hostname_characters=/[^a-zA-Z0-9\.\-:_]/;d.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src",audio:"src",video:"src"};d.getDomAttribute=function(a){if(a&&a.nodeName){var b=a.nodeName.toLowerCase();if("input"!==b||"image"===a.type)return d.domAttributes[b]}};d.encode=F;d.decode=decodeURIComponent;d.iso8859= +function(){d.encode=escape;d.decode=unescape};d.unicode=function(){d.encode=F;d.decode=decodeURIComponent};d.characters={pathname:{encode:{expression:/%(24|26|2B|2C|3B|3D|3A|40)/ig,map:{"%24":"$","%26":"&","%2B":"+","%2C":",","%3B":";","%3D":"=","%3A":":","%40":"@"}},decode:{expression:/[\/\?#]/g,map:{"/":"%2F","?":"%3F","#":"%23"}}},reserved:{encode:{expression:/%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/ig,map:{"%3A":":","%2F":"/","%3F":"?","%23":"#","%5B":"[","%5D":"]","%40":"@", "%21":"!","%24":"$","%26":"&","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"="}}},urnpath:{encode:{expression:/%(21|24|27|28|29|2A|2B|2C|3B|3D|40)/ig,map:{"%21":"!","%24":"$","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"=","%40":"@"}},decode:{expression:/[\/\?#:]/g,map:{"/":"%2F","?":"%3F","#":"%23",":":"%3A"}}}};d.encodeQuery=function(a,b){var c=d.encode(a+"");void 0===b&&(b=d.escapeQuerySpace);return b?c.replace(/%20/g,"+"):c};d.decodeQuery= -function(a,b){a+="";void 0===b&&(b=d.escapeQuerySpace);try{return d.decode(b?a.replace(/\+/g,"%20"):a)}catch(c){return a}};var I={encode:"encode",decode:"decode"},n,y=function(a,b){return function(c){try{return d[b](c+"").replace(d.characters[a][b].expression,function(e){return d.characters[a][b].map[e]})}catch(e){return c}}};for(n in I)d[n+"PathSegment"]=y("pathname",I[n]),d[n+"UrnPathSegment"]=y("urnpath",I[n]);I=function(a,b,c){return function(e){var f=c?function(J){return d[b](d[c](J))}:d[b]; -e=(e+"").split(a);for(var t=0,D=e.length;te)return a.charAt(0)===b.charAt(0)&&"/"===a.charAt(0)?"/":"";if("/"!==a.charAt(e)||"/"!==b.charAt(e))e=a.substring(0,e).lastIndexOf("/");return a.substring(0,e+1)};d.withinString=function(a,b,c){c||(c={});var e=c.start||d.findUri.start,f=c.end||d.findUri.end,t=c.trim||d.findUri.trim,D= -c.parens||d.findUri.parens,J=/[a-z0-9-]=["']?$/i;for(e.lastIndex=0;;){var L=e.exec(a);if(!L)break;var P=L.index;if(c.ignoreHtml){var N=a.slice(Math.max(P-3,0),P);if(N&&J.test(N))continue}var O=P+a.slice(P).search(f);N=a.slice(P,O);for(O=-1;;){var Q=D.exec(N);if(!Q)break;O=Math.max(O,Q.index+Q[0].length)}N=-1b))throw new TypeError('Port "'+a+'" is not a valid port');}};d.noConflict=function(a){if(a)return a={URI:this.noConflict()},p.URITemplate&&"function"===typeof p.URITemplate.noConflict&&(a.URITemplate=p.URITemplate.noConflict()),p.IPv6&&"function"===typeof p.IPv6.noConflict&&(a.IPv6=p.IPv6.noConflict()),p.SecondLevelDomains&&"function"===typeof p.SecondLevelDomains.noConflict&&(a.SecondLevelDomains=p.SecondLevelDomains.noConflict()), -a;p.URI===this&&(p.URI=z);return this};g.build=function(a){if(!0===a)this._deferred_build=!0;else if(void 0===a||this._deferred_build)this._string=d.build(this._parts),this._deferred_build=!1;return this};g.clone=function(){return new d(this)};g.valueOf=g.toString=function(){return this.build(!1)._string};g.protocol=x("protocol");g.username=x("username");g.password=x("password");g.hostname=x("hostname");g.port=x("port");g.query=B("query","?");g.fragment=B("fragment","#");g.search=function(a,b){var c= +c){var e="",f,n;for(f in a)if(B.call(a,f))if(A(a[f])){var z={};var I=0;for(n=a[f].length;Ie)return a.charAt(0)===b.charAt(0)&&"/"===a.charAt(0)?"/":"";if("/"!==a.charAt(e)||"/"!==b.charAt(e))e=a.substring(0,e).lastIndexOf("/");return a.substring(0,e+1)};d.withinString=function(a,b,c){c||(c={});var e=c.start||d.findUri.start,f=c.end||d.findUri.end,n=c.trim||d.findUri.trim,z= +c.parens||d.findUri.parens,I=/[a-z0-9-]=["']?$/i;for(e.lastIndex=0;;){var L=e.exec(a);if(!L)break;var P=L.index;if(c.ignoreHtml){var N=a.slice(Math.max(P-3,0),P);if(N&&I.test(N))continue}var O=P+a.slice(P).search(f);N=a.slice(P,O);for(O=-1;;){var Q=z.exec(N);if(!Q)break;O=Math.max(O,Q.index+Q[0].length)}N=-1b))throw new TypeError('Port "'+a+'" is not a valid port');}};d.noConflict=function(a){if(a)return a={URI:this.noConflict()},m.URITemplate&&"function"===typeof m.URITemplate.noConflict&&(a.URITemplate=m.URITemplate.noConflict()),m.IPv6&&"function"===typeof m.IPv6.noConflict&&(a.IPv6=m.IPv6.noConflict()),m.SecondLevelDomains&&"function"===typeof m.SecondLevelDomains.noConflict&&(a.SecondLevelDomains=m.SecondLevelDomains.noConflict()), +a;m.URI===this&&(m.URI=v);return this};g.build=function(a){if(!0===a)this._deferred_build=!0;else if(void 0===a||this._deferred_build)this._string=d.build(this._parts),this._deferred_build=!1;return this};g.clone=function(){return new d(this)};g.valueOf=g.toString=function(){return this.build(!1)._string};g.protocol=w("protocol");g.username=w("username");g.password=w("password");g.hostname=w("hostname");g.port=w("port");g.query=H("query","?");g.fragment=H("fragment","#");g.search=function(a,b){var c= this.query(a,b);return"string"===typeof c&&c.length?"?"+c:c};g.hash=function(a,b){var c=this.fragment(a,b);return"string"===typeof c&&c.length?"#"+c:c};g.pathname=function(a,b){if(void 0===a||!0===a){var c=this._parts.path||(this._parts.hostname?"/":"");return a?(this._parts.urn?d.decodeUrnPath:d.decodePath)(c):c}this._parts.path=this._parts.urn?a?d.recodeUrnPath(a):"":a?d.recodePath(a):"/";this.build(!b);return this};g.path=g.pathname;g.href=function(a,b){var c;if(void 0===a)return this.toString(); -this._string="";this._parts=d._parts();var e=a instanceof d,f="object"===typeof a&&(a.hostname||a.path||a.pathname);a.nodeName&&(f=d.getDomAttribute(a),a=a[f]||"",f=!1);!e&&f&&void 0!==a.pathname&&(a=a.toString());if("string"===typeof a||a instanceof String)this._parts=d.parse(String(a),this._parts);else if(e||f){e=e?a._parts:a;for(c in e)"query"!==c&&G.call(this._parts,c)&&(this._parts[c]=e[c]);e.query&&this.query(e.query,!1)}else throw new TypeError("invalid input");this.build(!b);return this}; -g.is=function(a){var b=!1,c=!1,e=!1,f=!1,t=!1,D=!1,J=!1,L=!this._parts.urn;this._parts.hostname&&(L=!1,c=d.ip4_expression.test(this._parts.hostname),e=d.ip6_expression.test(this._parts.hostname),b=c||e,t=(f=!b)&&k&&k.has(this._parts.hostname),D=f&&d.idn_expression.test(this._parts.hostname),J=f&&d.punycode_expression.test(this._parts.hostname));switch(a.toLowerCase()){case "relative":return L;case "absolute":return!L;case "domain":case "name":return f;case "sld":return t;case "ip":return b;case "ip4":case "ipv4":case "inet4":return c; -case "ip6":case "ipv6":case "inet6":return e;case "idn":return D;case "url":return!this._parts.urn;case "urn":return!!this._parts.urn;case "punycode":return J}return null};var H=g.protocol,C=g.port,K=g.hostname;g.protocol=function(a,b){if(a&&(a=a.replace(/:(\/\/)?$/,""),!a.match(d.protocol_expression)))throw new TypeError('Protocol "'+a+"\" contains characters other than [A-Z0-9.+-] or doesn't start with [A-Z]");return H.call(this,a,b)};g.scheme=g.protocol;g.port=function(a,b){if(this._parts.urn)return void 0=== -a?"":this;void 0!==a&&(0===a&&(a=null),a&&(a+="",":"===a.charAt(0)&&(a=a.substring(1)),d.ensureValidPort(a)));return C.call(this,a,b)};g.hostname=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0!==a){var c={preventInvalidHostname:this._parts.preventInvalidHostname};if("/"!==d.parseHost(a,c))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]');a=c.hostname;this._parts.preventInvalidHostname&&d.ensureValidHostname(a,this._parts.protocol)}return K.call(this, +this._string="";this._parts=d._parts();var e=a instanceof d,f="object"===typeof a&&(a.hostname||a.path||a.pathname);a.nodeName&&(f=d.getDomAttribute(a),a=a[f]||"",f=!1);!e&&f&&void 0!==a.pathname&&(a=a.toString());if("string"===typeof a||a instanceof String)this._parts=d.parse(String(a),this._parts);else if(e||f){e=e?a._parts:a;for(c in e)"query"!==c&&B.call(this._parts,c)&&(this._parts[c]=e[c]);e.query&&this.query(e.query,!1)}else throw new TypeError("invalid input");this.build(!b);return this}; +g.is=function(a){var b=!1,c=!1,e=!1,f=!1,n=!1,z=!1,I=!1,L=!this._parts.urn;this._parts.hostname&&(L=!1,c=d.ip4_expression.test(this._parts.hostname),e=d.ip6_expression.test(this._parts.hostname),b=c||e,n=(f=!b)&&k&&k.has(this._parts.hostname),z=f&&d.idn_expression.test(this._parts.hostname),I=f&&d.punycode_expression.test(this._parts.hostname));switch(a.toLowerCase()){case "relative":return L;case "absolute":return!L;case "domain":case "name":return f;case "sld":return n;case "ip":return b;case "ip4":case "ipv4":case "inet4":return c; +case "ip6":case "ipv6":case "inet6":return e;case "idn":return z;case "url":return!this._parts.urn;case "urn":return!!this._parts.urn;case "punycode":return I}return null};var C=g.protocol,y=g.port,J=g.hostname;g.protocol=function(a,b){if(a&&(a=a.replace(/:(\/\/)?$/,""),!a.match(d.protocol_expression)))throw new TypeError('Protocol "'+a+"\" contains characters other than [A-Z0-9.+-] or doesn't start with [A-Z]");return C.call(this,a,b)};g.scheme=g.protocol;g.port=function(a,b){if(this._parts.urn)return void 0=== +a?"":this;void 0!==a&&(0===a&&(a=null),a&&(a+="",":"===a.charAt(0)&&(a=a.substring(1)),d.ensureValidPort(a)));return y.call(this,a,b)};g.hostname=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0!==a){var c={preventInvalidHostname:this._parts.preventInvalidHostname};if("/"!==d.parseHost(a,c))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]');a=c.hostname;this._parts.preventInvalidHostname&&d.ensureValidHostname(a,this._parts.protocol)}return J.call(this, a,b)};g.origin=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){var c=this.protocol();return this.authority()?(c?c+"://":"")+this.authority():""}c=d(a);this.protocol(c.protocol()).authority(c.authority()).build(!b);return this};g.host=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a)return this._parts.hostname?d.buildHost(this._parts):"";if("/"!==d.parseHost(a,this._parts))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]'); this.build(!b);return this};g.authority=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a)return this._parts.hostname?d.buildAuthority(this._parts):"";if("/"!==d.parseAuthority(a,this._parts))throw new TypeError('Hostname "'+a+'" contains characters other than [A-Z0-9.-]');this.build(!b);return this};g.userinfo=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){var c=d.buildUserinfo(this._parts);return c?c.substring(0,c.length-1):c}"@"!==a[a.length-1]&& (a+="@");d.parseUserinfo(a,this._parts);this.build(!b);return this};g.resource=function(a,b){if(void 0===a)return this.path()+this.search()+this.hash();var c=d.parse(a);this._parts.path=c.path;this._parts.query=c.query;this._parts.fragment=c.fragment;this.build(!b);return this};g.subdomain=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var c=this._parts.hostname.length-this.domain().length-1;return this._parts.hostname.substring(0, -c)||""}c=this._parts.hostname.length-this.domain().length;c=this._parts.hostname.substring(0,c);c=new RegExp("^"+v(c));a&&"."!==a.charAt(a.length-1)&&(a+=".");if(-1!==a.indexOf(":"))throw new TypeError("Domains cannot contain colons");a&&d.ensureValidHostname(a,this._parts.protocol);this._parts.hostname=this._parts.hostname.replace(c,a);this.build(!b);return this};g.domain=function(a,b){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(b=a,a=void 0);if(void 0===a){if(!this._parts.hostname|| -this.is("IP"))return"";var c=this._parts.hostname.match(/\./g);if(c&&2>c.length)return this._parts.hostname;c=this._parts.hostname.length-this.tld(b).length-1;c=this._parts.hostname.lastIndexOf(".",c-1)+1;return this._parts.hostname.substring(c)||""}if(!a)throw new TypeError("cannot set domain empty");if(-1!==a.indexOf(":"))throw new TypeError("Domains cannot contain colons");d.ensureValidHostname(a,this._parts.protocol);!this._parts.hostname||this.is("IP")?this._parts.hostname=a:(c=new RegExp(v(this.domain())+ -"$"),this._parts.hostname=this._parts.hostname.replace(c,a));this.build(!b);return this};g.tld=function(a,b){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(b=a,a=void 0);if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var c=this._parts.hostname.lastIndexOf(".");c=this._parts.hostname.substring(c+1);return!0!==b&&k&&k.list[c.toLowerCase()]?k.get(this._parts.hostname)||c:c}if(a)if(a.match(/[^a-zA-Z0-9-]/))if(k&&k.is(a))c=new RegExp(v(this.tld())+"$"),this._parts.hostname= -this._parts.hostname.replace(c,a);else throw new TypeError('TLD "'+a+'" contains characters other than [A-Z0-9]');else{if(!this._parts.hostname||this.is("IP"))throw new ReferenceError("cannot set TLD on non-domain host");c=new RegExp(v(this.tld())+"$");this._parts.hostname=this._parts.hostname.replace(c,a)}else throw new TypeError("cannot set TLD empty");this.build(!b);return this};g.directory=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path&& -!this._parts.hostname)return"";if("/"===this._parts.path)return"/";var c=this._parts.path.length-this.filename().length-1;c=this._parts.path.substring(0,c)||(this._parts.hostname?"/":"");return a?d.decodePath(c):c}c=this._parts.path.length-this.filename().length;c=this._parts.path.substring(0,c);c=new RegExp("^"+v(c));this.is("relative")||(a||(a="/"),"/"!==a.charAt(0)&&(a="/"+a));a&&"/"!==a.charAt(a.length-1)&&(a+="/");a=d.recodePath(a);this._parts.path=this._parts.path.replace(c,a);this.build(!b); -return this};g.filename=function(a,b){if(this._parts.urn)return void 0===a?"":this;if("string"!==typeof a){if(!this._parts.path||"/"===this._parts.path)return"";var c=this._parts.path.lastIndexOf("/");c=this._parts.path.substring(c+1);return a?d.decodePathSegment(c):c}c=!1;"/"===a.charAt(0)&&(a=a.substring(1));a.match(/\.?\//)&&(c=!0);var e=new RegExp(v(this.filename())+"$");a=d.recodePath(a);this._parts.path=this._parts.path.replace(e,a);c?this.normalizePath(b):this.build(!b);return this};g.suffix= -function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path||"/"===this._parts.path)return"";var c=this.filename(),e=c.lastIndexOf(".");if(-1===e)return"";c=c.substring(e+1);c=/^[a-z0-9%]+$/i.test(c)?c:"";return a?d.decodePathSegment(c):c}"."===a.charAt(0)&&(a=a.substring(1));if(c=this.suffix())e=a?new RegExp(v(c)+"$"):new RegExp(v("."+c)+"$");else{if(!a)return this;this._parts.path+="."+d.recodePath(a)}e&&(a=d.recodePath(a),this._parts.path=this._parts.path.replace(e, -a));this.build(!b);return this};g.segment=function(a,b,c){var e=this._parts.urn?":":"/",f=this.path(),t="/"===f.substring(0,1);f=f.split(e);void 0!==a&&"number"!==typeof a&&(c=b,b=a,a=void 0);if(void 0!==a&&"number"!==typeof a)throw Error('Bad segment "'+a+'", must be 0-based integer');t&&f.shift();0>a&&(a=Math.max(f.length+a,0));if(void 0===b)return void 0===a?f:f[a];if(null===a||void 0===f[a])if(A(b)){f=[];a=0;for(var D=b.length;ac.length)return this._parts.hostname;c=this._parts.hostname.length-this.tld(b).length-1;c=this._parts.hostname.lastIndexOf(".",c-1)+1;return this._parts.hostname.substring(c)||""}if(!a)throw new TypeError("cannot set domain empty");if(-1!==a.indexOf(":"))throw new TypeError("Domains cannot contain colons");d.ensureValidHostname(a,this._parts.protocol);!this._parts.hostname||this.is("IP")?this._parts.hostname=a:(c=new RegExp(q(this.domain())+ +"$"),this._parts.hostname=this._parts.hostname.replace(c,a));this.build(!b);return this};g.tld=function(a,b){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(b=a,a=void 0);if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var c=this._parts.hostname.lastIndexOf(".");c=this._parts.hostname.substring(c+1);return!0!==b&&k&&k.list[c.toLowerCase()]?k.get(this._parts.hostname)||c:c}if(a)if(a.match(/[^a-zA-Z0-9-]/))if(k&&k.is(a))c=new RegExp(q(this.tld())+"$"),this._parts.hostname= +this._parts.hostname.replace(c,a);else throw new TypeError('TLD "'+a+'" contains characters other than [A-Z0-9]');else{if(!this._parts.hostname||this.is("IP"))throw new ReferenceError("cannot set TLD on non-domain host");c=new RegExp(q(this.tld())+"$");this._parts.hostname=this._parts.hostname.replace(c,a)}else throw new TypeError("cannot set TLD empty");this.build(!b);return this};g.directory=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path&& +!this._parts.hostname)return"";if("/"===this._parts.path)return"/";var c=this._parts.path.length-this.filename().length-1;c=this._parts.path.substring(0,c)||(this._parts.hostname?"/":"");return a?d.decodePath(c):c}c=this._parts.path.length-this.filename().length;c=this._parts.path.substring(0,c);c=new RegExp("^"+q(c));this.is("relative")||(a||(a="/"),"/"!==a.charAt(0)&&(a="/"+a));a&&"/"!==a.charAt(a.length-1)&&(a+="/");a=d.recodePath(a);this._parts.path=this._parts.path.replace(c,a);this.build(!b); +return this};g.filename=function(a,b){if(this._parts.urn)return void 0===a?"":this;if("string"!==typeof a){if(!this._parts.path||"/"===this._parts.path)return"";var c=this._parts.path.lastIndexOf("/");c=this._parts.path.substring(c+1);return a?d.decodePathSegment(c):c}c=!1;"/"===a.charAt(0)&&(a=a.substring(1));a.match(/\.?\//)&&(c=!0);var e=new RegExp(q(this.filename())+"$");a=d.recodePath(a);this._parts.path=this._parts.path.replace(e,a);c?this.normalizePath(b):this.build(!b);return this};g.suffix= +function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path||"/"===this._parts.path)return"";var c=this.filename(),e=c.lastIndexOf(".");if(-1===e)return"";c=c.substring(e+1);c=/^[a-z0-9%]+$/i.test(c)?c:"";return a?d.decodePathSegment(c):c}"."===a.charAt(0)&&(a=a.substring(1));if(c=this.suffix())e=a?new RegExp(q(c)+"$"):new RegExp(q("."+c)+"$");else{if(!a)return this;this._parts.path+="."+d.recodePath(a)}e&&(a=d.recodePath(a),this._parts.path=this._parts.path.replace(e, +a));this.build(!b);return this};g.segment=function(a,b,c){var e=this._parts.urn?":":"/",f=this.path(),n="/"===f.substring(0,1);f=f.split(e);void 0!==a&&"number"!==typeof a&&(c=b,b=a,a=void 0);if(void 0!==a&&"number"!==typeof a)throw Error('Bad segment "'+a+'", must be 0-based integer');n&&f.shift();0>a&&(a=Math.max(f.length+a,0));if(void 0===b)return void 0===a?f:f[a];if(null===a||void 0===f[a])if(A(b)){f=[];a=0;for(var z=b.length;a{}"`^| \\]/;k.expand=function(l,r,F){var h=A[l.operator],q=h.named?"Named":"Unnamed";l=l.variables;var u=[],x,B;for(B=0;x=l[B];B++){var z=r.get(x.name);if(0===z.type&&F&&F.strict)throw Error('Missing expansion value for variable "'+ -x.name+'"');if(z.val.length){if(1{}"`^| \\]/;k.expand=function(h,p,D){var u=A[h.operator],K=u.named?"Named":"Unnamed";h=h.variables;var F=[],w,H;for(H=0;w=h[H];H++){var v=p.get(w.name);if(0===v.type&&D&&D.strict)throw Error('Missing expansion value for variable "'+ +w.name+'"');if(v.val.length){if(1