Skip to content

Commit

Permalink
Add the host property
Browse files Browse the repository at this point in the history
The resource will reflect the hostname, while the host will contain domain:port
  • Loading branch information
IonicaBizau committed Jul 25, 2022
1 parent 02995c6 commit 31f7a33
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -28,6 +29,7 @@ function parsePath(url) {
, protocol: null
, port: null
, resource: ""
, host: ""
, user: ""
, password: ""
, pathname: ""
Expand All @@ -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
Expand Down
17 changes: 17 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const INPUTS = [
, protocol: "http"
, port: ""
, resource: "ionicabizau.net"
, host: "ionicabizau.net"
, user: ""
, pathname: "/blog"
, hash: ""
Expand All @@ -26,6 +27,7 @@ const INPUTS = [
, protocol: "http"
, port: ""
, resource: "subdomain.ionicabizau.net"
, host: "subdomain.ionicabizau.net"
, user: ""
, pathname: "/blog"
, hash: ""
Expand All @@ -41,6 +43,7 @@ const INPUTS = [
, protocol: "http"
, port: ""
, resource: "ionicabizau.net"
, host: "ionicabizau.net"
, user: ""
, pathname: "/blog"
, hash: ""
Expand All @@ -56,6 +59,7 @@ const INPUTS = [
, protocol: "http"
, port: ""
, resource: "domain.com"
, host: "domain.com"
, user: ""
, pathname: "/path/name"
, hash: "some-hash"
Expand All @@ -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"
Expand All @@ -86,6 +91,7 @@ const INPUTS = [
, protocol: "git"
, port: ""
, resource: "host.xz"
, host: "host.xz"
, user: "git"
, pathname: "/path/name.git"
, hash: ""
Expand All @@ -103,6 +109,7 @@ const INPUTS = [
, protocol: "file"
, port: ""
, resource: ""
, host: ""
, user: ""
, pathname: ""
, hash: ""
Expand All @@ -118,6 +125,7 @@ const INPUTS = [
, protocol: "file"
, port: ""
, resource: ""
, host: ""
, user: ""
, pathname: ""
, hash: ""
Expand All @@ -133,6 +141,7 @@ const INPUTS = [
, protocol: "file"
, port: ""
, resource: ""
, host: ""
, user: ""
, pathname: ""
, hash: ""
Expand All @@ -148,6 +157,7 @@ const INPUTS = [
, protocol: "file"
, port: ""
, resource: ""
, host: ""
, user: ""
, pathname: ""
, hash: ""
Expand All @@ -163,6 +173,7 @@ const INPUTS = [
, protocol: "file"
, port: ""
, resource: ""
, host: ""
, user: ""
, pathname: ""
, hash: ""
Expand All @@ -178,6 +189,7 @@ const INPUTS = [
, protocol: "file"
, port: ""
, resource: ""
, host: ""
, user: ""
, pathname: ""
, hash: ""
Expand All @@ -192,6 +204,7 @@ const INPUTS = [
, protocol: "file"
, port: ""
, resource: ""
, host: ""
, user: ""
, pathname: ""
, hash: ""
Expand All @@ -206,6 +219,7 @@ const INPUTS = [
, protocol: "file"
, port: ""
, resource: ""
, host: ""
, user: ""
, pathname: ""
, hash: ""
Expand All @@ -220,6 +234,7 @@ const INPUTS = [
, protocol: "https"
, port: ""
, resource: "attacker.com"
, host: "attacker.com"
, user: ""
, pathname: "/@example.com"
, hash: ""
Expand All @@ -234,6 +249,7 @@ const INPUTS = [
, protocol: "javascript"
, port: ""
, resource: "%0aalert(1)"
, host: "%0aalert(1)"
, user: ""
, pathname: ""
, hash: ""
Expand All @@ -248,6 +264,7 @@ const INPUTS = [
, protocol: "https"
, port: "89"
, resource: "github.com"
, host: "github.com:89"
, user: ""
, pathname: "/org/repo.git"
, hash: ""
Expand Down

0 comments on commit 31f7a33

Please sign in to comment.