Comparing version 1.4.7 to 1.5.0
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.URLParse = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ | ||
(function (global){ | ||
(function (global){(function (){ | ||
'use strict'; | ||
@@ -7,4 +7,4 @@ | ||
, qs = require('querystringify') | ||
, slashes = /^[A-Za-z][A-Za-z0-9+-.]*:\/\// | ||
, protocolre = /^([a-z][a-z0-9.+-]*:)?(\/\/)?([\S\s]*)/i | ||
, slashes = /^[A-Za-z][A-Za-z0-9+-.]*:[\\/]+/ | ||
, protocolre = /^([a-z][a-z0-9.+-]*:)?([\\/]{1,})?([\S\s]*)/i | ||
, whitespace = '[\\x09\\x0A\\x0B\\x0C\\x0D\\x20\\xA0\\u1680\\u180E\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200A\\u202F\\u205F\\u3000\\u2028\\u2029\\uFEFF]' | ||
@@ -121,7 +121,10 @@ , left = new RegExp('^'+ whitespace +'+'); | ||
address = trimLeft(address); | ||
var match = protocolre.exec(address); | ||
var match = protocolre.exec(address) | ||
, protocol = match[1] ? match[1].toLowerCase() : '' | ||
, slashes = !!(match[2] && match[2].length >= 2); | ||
return { | ||
protocol: match[1] ? match[1].toLowerCase() : '', | ||
slashes: !!match[2], | ||
protocol: protocol, | ||
slashes: slashes, | ||
rest: match[3] | ||
@@ -288,2 +291,10 @@ }; | ||
// | ||
// Default to a / for pathname if none exists. This normalizes the URL | ||
// to always have a / | ||
// | ||
if (url.pathname.charAt(0) !== '/' && url.hostname) { | ||
url.pathname = '/' + url.pathname; | ||
} | ||
// | ||
// We should not add port numbers if they are already the default port number | ||
@@ -457,7 +468,8 @@ // for a given protocol. As the host also contains the port number we're going | ||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | ||
}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | ||
},{"querystringify":2,"requires-port":3}],2:[function(require,module,exports){ | ||
'use strict'; | ||
var has = Object.prototype.hasOwnProperty; | ||
var has = Object.prototype.hasOwnProperty | ||
, undef; | ||
@@ -468,10 +480,29 @@ /** | ||
* @param {String} input The URI encoded string. | ||
* @returns {String} The decoded string. | ||
* @returns {String|Null} The decoded string. | ||
* @api private | ||
*/ | ||
function decode(input) { | ||
return decodeURIComponent(input.replace(/\+/g, ' ')); | ||
try { | ||
return decodeURIComponent(input.replace(/\+/g, ' ')); | ||
} catch (e) { | ||
return null; | ||
} | ||
} | ||
/** | ||
* Attempts to encode a given input. | ||
* | ||
* @param {String} input The string that needs to be encoded. | ||
* @returns {String|Null} The encoded string. | ||
* @api private | ||
*/ | ||
function encode(input) { | ||
try { | ||
return encodeURIComponent(input); | ||
} catch (e) { | ||
return null; | ||
} | ||
} | ||
/** | ||
* Simple query string parser. | ||
@@ -484,3 +515,3 @@ * | ||
function querystring(query) { | ||
var parser = /([^=?&]+)=?([^&]*)/g | ||
var parser = /([^=?#&]+)=?([^&]*)/g | ||
, result = {} | ||
@@ -498,3 +529,6 @@ , part; | ||
// | ||
if (key in result) continue; | ||
// In the case if failed decoding, we want to omit the key/value pairs | ||
// from the result. | ||
// | ||
if (key === null || value === null || key in result) continue; | ||
result[key] = value; | ||
@@ -517,3 +551,5 @@ } | ||
var pairs = []; | ||
var pairs = [] | ||
, value | ||
, key; | ||
@@ -525,5 +561,23 @@ // | ||
for (var key in obj) { | ||
for (key in obj) { | ||
if (has.call(obj, key)) { | ||
pairs.push(encodeURIComponent(key) +'='+ encodeURIComponent(obj[key])); | ||
value = obj[key]; | ||
// | ||
// Edge cases where we actually want to encode the value to an empty | ||
// string instead of the stringified value. | ||
// | ||
if (!value && (value === null || value === undef || isNaN(value))) { | ||
value = ''; | ||
} | ||
key = encode(key); | ||
value = encode(value); | ||
// | ||
// If we failed to encode the strings, we should bail out as we don't | ||
// want to add invalid strings to the query. | ||
// | ||
if (key === null || value === null) continue; | ||
pairs.push(key +'='+ value); | ||
} | ||
@@ -530,0 +584,0 @@ } |
@@ -1,1 +0,1 @@ | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).URLParse=e()}}(function(){return function s(a,i,u){function f(t,e){if(!i[t]){if(!a[t]){var o="function"==typeof require&&require;if(!e&&o)return o(t,!0);if(p)return p(t,!0);var r=new Error("Cannot find module '"+t+"'");throw r.code="MODULE_NOT_FOUND",r}var n=i[t]={exports:{}};a[t][0].call(n.exports,function(e){return f(a[t][1][e]||e)},n,n.exports,s,a,i,u)}return i[t].exports}for(var p="function"==typeof require&&require,e=0;e<u.length;e++)f(u[e]);return f}({1:[function(e,r,t){(function(s){"use strict";var h=e("requires-port"),d=e("querystringify"),a=/^[A-Za-z][A-Za-z0-9+-.]*:\/\//,o=/^([a-z][a-z0-9.+-]*:)?(\/\/)?([\S\s]*)/i,t=new RegExp("^[\\x09\\x0A\\x0B\\x0C\\x0D\\x20\\xA0\\u1680\\u180E\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200A\\u202F\\u205F\\u3000\\u2028\\u2029\\uFEFF]+");function y(e){return(e||"").toString().replace(t,"")}var m=[["#","hash"],["?","query"],function(e){return e.replace("\\","/")},["/","pathname"],["@","auth",1],[NaN,"host",void 0,1,1],[/:(\d+)$/,"port",void 0,1],[NaN,"hostname",void 0,1,1]],i={hash:1,query:1};function w(e){var t,o=("undefined"!=typeof window?window:void 0!==s?s:"undefined"!=typeof self?self:{}).location||{},r={},n=typeof(e=e||o);if("blob:"===e.protocol)r=new v(unescape(e.pathname),{});else if("string"===n)for(t in r=new v(e,{}),i)delete r[t];else if("object"===n){for(t in e)t in i||(r[t]=e[t]);void 0===r.slashes&&(r.slashes=a.test(e.href))}return r}function g(e){e=y(e);var t=o.exec(e);return{protocol:t[1]?t[1].toLowerCase():"",slashes:!!t[2],rest:t[3]}}function v(e,t,o){if(e=y(e),!(this instanceof v))return new v(e,t,o);var r,n,s,a,i,u,f=m.slice(),p=typeof t,c=this,l=0;for("object"!==p&&"string"!==p&&(o=t,t=null),o&&"function"!=typeof o&&(o=d.parse),t=w(t),r=!(n=g(e||"")).protocol&&!n.slashes,c.slashes=n.slashes||r&&t.slashes,c.protocol=n.protocol||t.protocol||"",e=n.rest,n.slashes||(f[3]=[/(.*)/,"pathname"]);l<f.length;l++)"function"!=typeof(a=f[l])?(s=a[0],u=a[1],s!=s?c[u]=e:"string"==typeof s?~(i=e.indexOf(s))&&("number"==typeof a[2]?(c[u]=e.slice(0,i),e=e.slice(i+a[2])):(c[u]=e.slice(i),e=e.slice(0,i))):(i=s.exec(e))&&(c[u]=i[1],e=e.slice(0,i.index)),c[u]=c[u]||r&&a[3]&&t[u]||"",a[4]&&(c[u]=c[u].toLowerCase())):e=a(e);o&&(c.query=o(c.query)),r&&t.slashes&&"/"!==c.pathname.charAt(0)&&(""!==c.pathname||""!==t.pathname)&&(c.pathname=function(e,t){if(""===e)return t;for(var o=(t||"/").split("/").slice(0,-1).concat(e.split("/")),r=o.length,n=o[r-1],s=!1,a=0;r--;)"."===o[r]?o.splice(r,1):".."===o[r]?(o.splice(r,1),a++):a&&(0===r&&(s=!0),o.splice(r,1),a--);return s&&o.unshift(""),"."!==n&&".."!==n||o.push(""),o.join("/")}(c.pathname,t.pathname)),h(c.port,c.protocol)||(c.host=c.hostname,c.port=""),c.username=c.password="",c.auth&&(a=c.auth.split(":"),c.username=a[0]||"",c.password=a[1]||""),c.origin=c.protocol&&c.host&&"file:"!==c.protocol?c.protocol+"//"+c.host:"null",c.href=c.toString()}v.prototype={set:function(e,t,o){var r=this;switch(e){case"query":"string"==typeof t&&t.length&&(t=(o||d.parse)(t)),r[e]=t;break;case"port":r[e]=t,h(t,r.protocol)?t&&(r.host=r.hostname+":"+t):(r.host=r.hostname,r[e]="");break;case"hostname":r[e]=t,r.port&&(t+=":"+r.port),r.host=t;break;case"host":r[e]=t,/:\d+$/.test(t)?(t=t.split(":"),r.port=t.pop(),r.hostname=t.join(":")):(r.hostname=t,r.port="");break;case"protocol":r.protocol=t.toLowerCase(),r.slashes=!o;break;case"pathname":case"hash":if(t){var n="pathname"===e?"/":"#";r[e]=t.charAt(0)!==n?n+t:t}else r[e]=t;break;default:r[e]=t}for(var s=0;s<m.length;s++){var a=m[s];a[4]&&(r[a[1]]=r[a[1]].toLowerCase())}return r.origin=r.protocol&&r.host&&"file:"!==r.protocol?r.protocol+"//"+r.host:"null",r.href=r.toString(),r},toString:function(e){e&&"function"==typeof e||(e=d.stringify);var t,o=this,r=o.protocol;r&&":"!==r.charAt(r.length-1)&&(r+=":");var n=r+(o.slashes?"//":"");return o.username&&(n+=o.username,o.password&&(n+=":"+o.password),n+="@"),n+=o.host+o.pathname,(t="object"==typeof o.query?e(o.query):o.query)&&(n+="?"!==t.charAt(0)?"?"+t:t),o.hash&&(n+=o.hash),n}},v.extractProtocol=g,v.location=w,v.trimLeft=y,v.qs=d,r.exports=v}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{querystringify:2,"requires-port":3}],2:[function(e,t,o){"use strict";var n=Object.prototype.hasOwnProperty;function a(e){return decodeURIComponent(e.replace(/\+/g," "))}o.stringify=function(e,t){t=t||"";var o=[];for(var r in"string"!=typeof t&&(t="?"),e)n.call(e,r)&&o.push(encodeURIComponent(r)+"="+encodeURIComponent(e[r]));return o.length?t+o.join("&"):""},o.parse=function(e){for(var t,o=/([^=?&]+)=?([^&]*)/g,r={};t=o.exec(e);){var n=a(t[1]),s=a(t[2]);n in r||(r[n]=s)}return r}},{}],3:[function(e,t,o){"use strict";t.exports=function(e,t){if(t=t.split(":")[0],!(e=+e))return!1;switch(t){case"http":case"ws":return 80!==e;case"https":case"wss":return 443!==e;case"ftp":return 21!==e;case"gopher":return 70!==e;case"file":return!1}return 0!==e}},{}]},{},[1])(1)}); | ||
!function(e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).URLParse=e()}(function(){return function n(r,s,a){function i(t,e){if(!s[t]){if(!r[t]){var o="function"==typeof require&&require;if(!e&&o)return o(t,!0);if(u)return u(t,!0);throw(o=new Error("Cannot find module '"+t+"'")).code="MODULE_NOT_FOUND",o}o=s[t]={exports:{}},r[t][0].call(o.exports,function(e){return i(r[t][1][e]||e)},o,o.exports,n,r,s,a)}return s[t].exports}for(var u="function"==typeof require&&require,e=0;e<a.length;e++)i(a[e]);return i}({1:[function(e,n,t){!function(a){!function(){"use strict";var f=e("requires-port"),h=e("querystringify"),r=/^[A-Za-z][A-Za-z0-9+-.]*:[\\/]+/,t=/^([a-z][a-z0-9.+-]*:)?([\\/]{1,})?([\S\s]*)/i,o=new RegExp("^[\\x09\\x0A\\x0B\\x0C\\x0D\\x20\\xA0\\u1680\\u180E\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200A\\u202F\\u205F\\u3000\\u2028\\u2029\\uFEFF]+");function d(e){return(e||"").toString().replace(o,"")}var y=[["#","hash"],["?","query"],function(e){return e.replace("\\","/")},["/","pathname"],["@","auth",1],[NaN,"host",void 0,1,1],[/:(\d+)$/,"port",void 0,1],[NaN,"hostname",void 0,1,1]],s={hash:1,query:1};function m(e){var t,o="undefined"!=typeof window?window:void 0!==a?a:"undefined"!=typeof self?self:{},o=o.location||{},n={},o=typeof(e=e||o);if("blob:"===e.protocol)n=new w(unescape(e.pathname),{});else if("string"==o)for(t in n=new w(e,{}),s)delete n[t];else if("object"==o){for(t in e)t in s||(n[t]=e[t]);void 0===n.slashes&&(n.slashes=r.test(e.href))}return n}function g(e){e=d(e);e=t.exec(e);return{protocol:e[1]?e[1].toLowerCase():"",slashes:!!(e[2]&&2<=e[2].length),rest:e[3]}}function w(e,t,o){if(e=d(e),!(this instanceof w))return new w(e,t,o);var n,r,s,a,i,u=y.slice(),c=typeof t,l=this,p=0;for("object"!=c&&"string"!=c&&(o=t,t=null),o&&"function"!=typeof o&&(o=h.parse),t=m(t),n=!(c=g(e||"")).protocol&&!c.slashes,l.slashes=c.slashes||n&&t.slashes,l.protocol=c.protocol||t.protocol||"",e=c.rest,c.slashes||(u[3]=[/(.*)/,"pathname"]);p<u.length;p++)"function"!=typeof(s=u[p])?(r=s[0],i=s[1],r!=r?l[i]=e:"string"==typeof r?~(a=e.indexOf(r))&&(e="number"==typeof s[2]?(l[i]=e.slice(0,a),e.slice(a+s[2])):(l[i]=e.slice(a),e.slice(0,a))):(a=r.exec(e))&&(l[i]=a[1],e=e.slice(0,a.index)),l[i]=l[i]||n&&s[3]&&t[i]||"",s[4]&&(l[i]=l[i].toLowerCase())):e=s(e);o&&(l.query=o(l.query)),n&&t.slashes&&"/"!==l.pathname.charAt(0)&&(""!==l.pathname||""!==t.pathname)&&(l.pathname=function(e,t){if(""===e)return t;for(var o=(t||"/").split("/").slice(0,-1).concat(e.split("/")),n=o.length,e=o[n-1],r=!1,s=0;n--;)"."===o[n]?o.splice(n,1):".."===o[n]?(o.splice(n,1),s++):s&&(0===n&&(r=!0),o.splice(n,1),s--);return r&&o.unshift(""),"."!==e&&".."!==e||o.push(""),o.join("/")}(l.pathname,t.pathname)),"/"!==l.pathname.charAt(0)&&l.hostname&&(l.pathname="/"+l.pathname),f(l.port,l.protocol)||(l.host=l.hostname,l.port=""),l.username=l.password="",l.auth&&(s=l.auth.split(":"),l.username=s[0]||"",l.password=s[1]||""),l.origin=l.protocol&&l.host&&"file:"!==l.protocol?l.protocol+"//"+l.host:"null",l.href=l.toString()}w.prototype={set:function(e,t,o){var n,r=this;switch(e){case"query":"string"==typeof t&&t.length&&(t=(o||h.parse)(t)),r[e]=t;break;case"port":r[e]=t,f(t,r.protocol)?t&&(r.host=r.hostname+":"+t):(r.host=r.hostname,r[e]="");break;case"hostname":r[e]=t,r.port&&(t+=":"+r.port),r.host=t;break;case"host":r[e]=t,/:\d+$/.test(t)?(t=t.split(":"),r.port=t.pop(),r.hostname=t.join(":")):(r.hostname=t,r.port="");break;case"protocol":r.protocol=t.toLowerCase(),r.slashes=!o;break;case"pathname":case"hash":t?(n="pathname"===e?"/":"#",r[e]=t.charAt(0)!==n?n+t:t):r[e]=t;break;default:r[e]=t}for(var s=0;s<y.length;s++){var a=y[s];a[4]&&(r[a[1]]=r[a[1]].toLowerCase())}return r.origin=r.protocol&&r.host&&"file:"!==r.protocol?r.protocol+"//"+r.host:"null",r.href=r.toString(),r},toString:function(e){e&&"function"==typeof e||(e=h.stringify);var t=this,o=t.protocol;return o&&":"!==o.charAt(o.length-1)&&(o+=":"),o+=t.slashes?"//":"",t.username&&(o+=t.username,t.password&&(o+=":"+t.password),o+="@"),o+=t.host+t.pathname,(e="object"==typeof t.query?e(t.query):t.query)&&(o+="?"!==e.charAt(0)?"?"+e:e),t.hash&&(o+=t.hash),o}},w.extractProtocol=g,w.location=m,w.trimLeft=d,w.qs=h,n.exports=w}.call(this)}.call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{querystringify:2,"requires-port":3}],2:[function(e,t,o){"use strict";var s=Object.prototype.hasOwnProperty;function a(e){try{return decodeURIComponent(e.replace(/\+/g," "))}catch(e){return null}}function i(e){try{return encodeURIComponent(e)}catch(e){return null}}o.stringify=function(e,t){var o,n,r=[];for(n in"string"!=typeof(t=t||"")&&(t="?"),e)s.call(e,n)&&((o=e[n])||null!=o&&!isNaN(o)||(o=""),n=i(n),o=i(o),null!==n&&null!==o&&r.push(n+"="+o));return r.length?t+r.join("&"):""},o.parse=function(e){for(var t=/([^=?#&]+)=?([^&]*)/g,o={};r=t.exec(e);){var n=a(r[1]),r=a(r[2]);null===n||null===r||n in o||(o[n]=r)}return o}},{}],3:[function(e,t,o){"use strict";t.exports=function(e,t){if(t=t.split(":")[0],!(e=+e))return!1;switch(t){case"http":case"ws":return 80!==e;case"https":case"wss":return 443!==e;case"ftp":return 21!==e;case"gopher":return 70!==e;case"file":return!1}return 0!==e}},{}]},{},[1])(1)}); |
21
index.js
@@ -5,4 +5,4 @@ 'use strict'; | ||
, qs = require('querystringify') | ||
, slashes = /^[A-Za-z][A-Za-z0-9+-.]*:\/\// | ||
, protocolre = /^([a-z][a-z0-9.+-]*:)?(\/\/)?([\S\s]*)/i | ||
, slashes = /^[A-Za-z][A-Za-z0-9+-.]*:[\\/]+/ | ||
, protocolre = /^([a-z][a-z0-9.+-]*:)?([\\/]{1,})?([\S\s]*)/i | ||
, whitespace = '[\\x09\\x0A\\x0B\\x0C\\x0D\\x20\\xA0\\u1680\\u180E\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200A\\u202F\\u205F\\u3000\\u2028\\u2029\\uFEFF]' | ||
@@ -119,7 +119,10 @@ , left = new RegExp('^'+ whitespace +'+'); | ||
address = trimLeft(address); | ||
var match = protocolre.exec(address); | ||
var match = protocolre.exec(address) | ||
, protocol = match[1] ? match[1].toLowerCase() : '' | ||
, slashes = !!(match[2] && match[2].length >= 2); | ||
return { | ||
protocol: match[1] ? match[1].toLowerCase() : '', | ||
slashes: !!match[2], | ||
protocol: protocol, | ||
slashes: slashes, | ||
rest: match[3] | ||
@@ -286,2 +289,10 @@ }; | ||
// | ||
// Default to a / for pathname if none exists. This normalizes the URL | ||
// to always have a / | ||
// | ||
if (url.pathname.charAt(0) !== '/' && url.hostname) { | ||
url.pathname = '/' + url.pathname; | ||
} | ||
// | ||
// We should not add port numbers if they are already the default port number | ||
@@ -288,0 +299,0 @@ // for a given protocol. As the host also contains the port number we're going |
{ | ||
"name": "url-parse", | ||
"version": "1.4.7", | ||
"version": "1.5.0", | ||
"description": "Small footprint URL parser that works seamlessly across Node.js and browser environments", | ||
@@ -9,3 +9,3 @@ "main": "index.js", | ||
"minify": "uglifyjs dist/url-parse.js --source-map -cm -o dist/url-parse.min.js", | ||
"test": "nyc --reporter=html --reporter=text mocha test/test.js", | ||
"test": "c8 --reporter=html --reporter=text mocha test/test.js", | ||
"test-browser": "node test/browser.js", | ||
@@ -43,4 +43,5 @@ "prepublishOnly": "npm run browserify && npm run minify", | ||
"browserify": "^16.2.3", | ||
"mocha": "^6.1.4", | ||
"nyc": "^14.0.0", | ||
"c8": "^7.3.1", | ||
"coveralls": "^3.1.0", | ||
"mocha": "^8.0.1", | ||
"pre-commit": "^1.2.2", | ||
@@ -47,0 +48,0 @@ "sauce-browsers": "^2.0.0", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52599
920
9