aboutsummaryrefslogtreecommitdiff
path: root/node_modules/urijs/src/URI.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/urijs/src/URI.js')
-rw-r--r--node_modules/urijs/src/URI.js61
1 files changed, 48 insertions, 13 deletions
diff --git a/node_modules/urijs/src/URI.js b/node_modules/urijs/src/URI.js
index 47e6d9a75..1d7957a00 100644
--- a/node_modules/urijs/src/URI.js
+++ b/node_modules/urijs/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;
@@ -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);
@@ -780,6 +793,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;
@@ -1297,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;
@@ -1337,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);
};
@@ -2285,6 +2315,11 @@
};
// state
+ p.preventInvalidHostname = function(v) {
+ this._parts.preventInvalidHostname = !!v;
+ return this;
+ };
+
p.duplicateQueryParameters = function(v) {
this._parts.duplicateQueryParameters = !!v;
return this;