Skip to content

Commit 31f7a33

Browse files
committed
Add the host property
The resource will reflect the hostname, while the host will contain domain:port
1 parent 02995c6 commit 31f7a33

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ const protocols = require("protocols")
1212
* - `protocols` (Array): An array with the url protocols (usually it has one element).
1313
* - `protocol` (String): The first protocol or `"file"`.
1414
* - `port` (String): The domain port (default: `""`).
15-
* - `resource` (String): The url domain (including subdomain and port).
15+
* - `resource` (String): The url domain/hostname.
16+
* - `host` (String): The url domain (including subdomain and port).
1617
* - `user` (String): The authentication user (default: `""`).
1718
* - `password` (String): The authentication password (default: `""`).
1819
* - `pathname` (String): The url pathname.
@@ -28,6 +29,7 @@ function parsePath(url) {
2829
, protocol: null
2930
, port: null
3031
, resource: ""
32+
, host: ""
3133
, user: ""
3234
, password: ""
3335
, pathname: ""
@@ -43,6 +45,7 @@ function parsePath(url) {
4345
output.protocol = output.protocols[0]
4446
output.port = parsed.port
4547
output.resource = parsed.hostname
48+
output.host = parsed.host
4649
output.user = parsed.username || ""
4750
output.password = parsed.password || ""
4851
output.pathname = parsed.pathname

test/index.js

+17
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const INPUTS = [
1111
, protocol: "http"
1212
, port: ""
1313
, resource: "ionicabizau.net"
14+
, host: "ionicabizau.net"
1415
, user: ""
1516
, pathname: "/blog"
1617
, hash: ""
@@ -26,6 +27,7 @@ const INPUTS = [
2627
, protocol: "http"
2728
, port: ""
2829
, resource: "subdomain.ionicabizau.net"
30+
, host: "subdomain.ionicabizau.net"
2931
, user: ""
3032
, pathname: "/blog"
3133
, hash: ""
@@ -41,6 +43,7 @@ const INPUTS = [
4143
, protocol: "http"
4244
, port: ""
4345
, resource: "ionicabizau.net"
46+
, host: "ionicabizau.net"
4447
, user: ""
4548
, pathname: "/blog"
4649
, hash: ""
@@ -56,6 +59,7 @@ const INPUTS = [
5659
, protocol: "http"
5760
, port: ""
5861
, resource: "domain.com"
62+
, host: "domain.com"
5963
, user: ""
6064
, pathname: "/path/name"
6165
, hash: "some-hash"
@@ -71,6 +75,7 @@ const INPUTS = [
7175
, protocol: "http"
7276
, port: ""
7377
, resource: "domain.com"
78+
, host: "domain.com"
7479
, user: ""
7580
, pathname: "/path/name"
7681
, hash: "some-hash?foo=bar&bar=42"
@@ -86,6 +91,7 @@ const INPUTS = [
8691
, protocol: "git"
8792
, port: ""
8893
, resource: "host.xz"
94+
, host: "host.xz"
8995
, user: "git"
9096
, pathname: "/path/name.git"
9197
, hash: ""
@@ -103,6 +109,7 @@ const INPUTS = [
103109
, protocol: "file"
104110
, port: ""
105111
, resource: ""
112+
, host: ""
106113
, user: ""
107114
, pathname: ""
108115
, hash: ""
@@ -118,6 +125,7 @@ const INPUTS = [
118125
, protocol: "file"
119126
, port: ""
120127
, resource: ""
128+
, host: ""
121129
, user: ""
122130
, pathname: ""
123131
, hash: ""
@@ -133,6 +141,7 @@ const INPUTS = [
133141
, protocol: "file"
134142
, port: ""
135143
, resource: ""
144+
, host: ""
136145
, user: ""
137146
, pathname: ""
138147
, hash: ""
@@ -148,6 +157,7 @@ const INPUTS = [
148157
, protocol: "file"
149158
, port: ""
150159
, resource: ""
160+
, host: ""
151161
, user: ""
152162
, pathname: ""
153163
, hash: ""
@@ -163,6 +173,7 @@ const INPUTS = [
163173
, protocol: "file"
164174
, port: ""
165175
, resource: ""
176+
, host: ""
166177
, user: ""
167178
, pathname: ""
168179
, hash: ""
@@ -178,6 +189,7 @@ const INPUTS = [
178189
, protocol: "file"
179190
, port: ""
180191
, resource: ""
192+
, host: ""
181193
, user: ""
182194
, pathname: ""
183195
, hash: ""
@@ -192,6 +204,7 @@ const INPUTS = [
192204
, protocol: "file"
193205
, port: ""
194206
, resource: ""
207+
, host: ""
195208
, user: ""
196209
, pathname: ""
197210
, hash: ""
@@ -206,6 +219,7 @@ const INPUTS = [
206219
, protocol: "file"
207220
, port: ""
208221
, resource: ""
222+
, host: ""
209223
, user: ""
210224
, pathname: ""
211225
, hash: ""
@@ -220,6 +234,7 @@ const INPUTS = [
220234
, protocol: "https"
221235
, port: ""
222236
, resource: "attacker.com"
237+
, host: "attacker.com"
223238
, user: ""
224239
, pathname: "/@example.com"
225240
, hash: ""
@@ -234,6 +249,7 @@ const INPUTS = [
234249
, protocol: "javascript"
235250
, port: ""
236251
, resource: "%0aalert(1)"
252+
, host: "%0aalert(1)"
237253
, user: ""
238254
, pathname: ""
239255
, hash: ""
@@ -248,6 +264,7 @@ const INPUTS = [
248264
, protocol: "https"
249265
, port: "89"
250266
, resource: "github.com"
267+
, host: "github.com:89"
251268
, user: ""
252269
, pathname: "/org/repo.git"
253270
, hash: ""

0 commit comments

Comments
 (0)