diff --git a/lib/index.js b/lib/index.js index 98a46fa..34c372c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -12,7 +12,8 @@ const protocols = require("protocols") * - `protocols` (Array): An array with the url protocols (usually it has one element). * - `protocol` (String): The first protocol or `"file"`. * - `port` (String): The domain port (default: `""`). - * - `resource` (String): The url domain (including subdomain and port). + * - `resource` (String): The url domain/hostname. + * - `host` (String): The url domain (including subdomain and port). * - `user` (String): The authentication user (default: `""`). * - `password` (String): The authentication password (default: `""`). * - `pathname` (String): The url pathname. @@ -28,6 +29,7 @@ function parsePath(url) { , protocol: null , port: null , resource: "" + , host: "" , user: "" , password: "" , pathname: "" @@ -43,6 +45,7 @@ function parsePath(url) { output.protocol = output.protocols[0] output.port = parsed.port output.resource = parsed.hostname + output.host = parsed.host output.user = parsed.username || "" output.password = parsed.password || "" output.pathname = parsed.pathname diff --git a/test/index.js b/test/index.js index 04686b4..3408707 100644 --- a/test/index.js +++ b/test/index.js @@ -11,6 +11,7 @@ const INPUTS = [ , protocol: "http" , port: "" , resource: "ionicabizau.net" + , host: "ionicabizau.net" , user: "" , pathname: "/blog" , hash: "" @@ -26,6 +27,7 @@ const INPUTS = [ , protocol: "http" , port: "" , resource: "subdomain.ionicabizau.net" + , host: "subdomain.ionicabizau.net" , user: "" , pathname: "/blog" , hash: "" @@ -41,6 +43,7 @@ const INPUTS = [ , protocol: "http" , port: "" , resource: "ionicabizau.net" + , host: "ionicabizau.net" , user: "" , pathname: "/blog" , hash: "" @@ -56,6 +59,7 @@ const INPUTS = [ , protocol: "http" , port: "" , resource: "domain.com" + , host: "domain.com" , user: "" , pathname: "/path/name" , hash: "some-hash" @@ -71,6 +75,7 @@ const INPUTS = [ , protocol: "http" , port: "" , resource: "domain.com" + , host: "domain.com" , user: "" , pathname: "/path/name" , hash: "some-hash?foo=bar&bar=42" @@ -86,6 +91,7 @@ const INPUTS = [ , protocol: "git" , port: "" , resource: "host.xz" + , host: "host.xz" , user: "git" , pathname: "/path/name.git" , hash: "" @@ -103,6 +109,7 @@ const INPUTS = [ , protocol: "file" , port: "" , resource: "" + , host: "" , user: "" , pathname: "" , hash: "" @@ -118,6 +125,7 @@ const INPUTS = [ , protocol: "file" , port: "" , resource: "" + , host: "" , user: "" , pathname: "" , hash: "" @@ -133,6 +141,7 @@ const INPUTS = [ , protocol: "file" , port: "" , resource: "" + , host: "" , user: "" , pathname: "" , hash: "" @@ -148,6 +157,7 @@ const INPUTS = [ , protocol: "file" , port: "" , resource: "" + , host: "" , user: "" , pathname: "" , hash: "" @@ -163,6 +173,7 @@ const INPUTS = [ , protocol: "file" , port: "" , resource: "" + , host: "" , user: "" , pathname: "" , hash: "" @@ -178,6 +189,7 @@ const INPUTS = [ , protocol: "file" , port: "" , resource: "" + , host: "" , user: "" , pathname: "" , hash: "" @@ -192,6 +204,7 @@ const INPUTS = [ , protocol: "file" , port: "" , resource: "" + , host: "" , user: "" , pathname: "" , hash: "" @@ -206,6 +219,7 @@ const INPUTS = [ , protocol: "file" , port: "" , resource: "" + , host: "" , user: "" , pathname: "" , hash: "" @@ -220,6 +234,7 @@ const INPUTS = [ , protocol: "https" , port: "" , resource: "attacker.com" + , host: "attacker.com" , user: "" , pathname: "/@example.com" , hash: "" @@ -234,6 +249,7 @@ const INPUTS = [ , protocol: "javascript" , port: "" , resource: "%0aalert(1)" + , host: "%0aalert(1)" , user: "" , pathname: "" , hash: "" @@ -248,6 +264,7 @@ const INPUTS = [ , protocol: "https" , port: "89" , resource: "github.com" + , host: "github.com:89" , user: "" , pathname: "/org/repo.git" , hash: ""