Skip to content

Commit 4bae19e

Browse files
committed
Add the parse_failed property.
This will propagate the fact that the native parser failed to parse the input.
1 parent 3d1525d commit 4bae19e

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const protocols = require("protocols")
2121
* - `search` (String): The url querystring value (excluding `?`).
2222
* - `href` (String): The normalized input url.
2323
* - `query` (Object): The url querystring, parsed as object.
24+
* - `parse_failed` (Boolean): Whether the parsing failed or not.
2425
*/
2526
function parsePath(url) {
2627

@@ -37,6 +38,7 @@ function parsePath(url) {
3738
, search: ""
3839
, href: url
3940
, query: {}
41+
, parse_failed: false
4042
}
4143

4244
try {
@@ -67,6 +69,7 @@ function parsePath(url) {
6769
output.search = ""
6870
output.href = url
6971
output.query = {}
72+
output.parse_failed = true
7073
}
7174

7275
return output;

test/index.js

+17
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const INPUTS = [
1818
, search: ""
1919
, href: "http://ionicabizau.net/blog"
2020
, query: {}
21+
, parse_failed: false
2122
}
2223
]
2324
, [
@@ -34,6 +35,7 @@ const INPUTS = [
3435
, search: ""
3536
, href: "http://subdomain.ionicabizau.net/blog"
3637
, query: {}
38+
, parse_failed: false
3739
}
3840
]
3941
, [
@@ -50,6 +52,7 @@ const INPUTS = [
5052
, search: ""
5153
, href: "http://ionicabizau.net/blog"
5254
, query: {}
55+
, parse_failed: false
5356
}
5457
]
5558
, [
@@ -65,6 +68,7 @@ const INPUTS = [
6568
, hash: "some-hash"
6669
, search: "foo=bar&bar=42"
6770
, query: { foo: "bar", bar: "42" }
71+
, parse_failed: false
6872
, href: "http://domain.com/path/name?foo=bar&bar=42#some-hash"
6973
}
7074
]
@@ -81,6 +85,7 @@ const INPUTS = [
8185
, hash: "some-hash?foo=bar&bar=42"
8286
, search: ""
8387
, query: {}
88+
, parse_failed: false
8489
, href: "http://domain.com/path/name#some-hash?foo=bar&bar=42"
8590
}
8691
]
@@ -97,6 +102,7 @@ const INPUTS = [
97102
, hash: ""
98103
, search: ""
99104
, query: {}
105+
, parse_failed: false
100106
, href: "git+ssh://[email protected]/path/name.git"
101107
}
102108
]
@@ -115,6 +121,7 @@ const INPUTS = [
115121
, hash: ""
116122
, search: ""
117123
, query: {}
124+
, parse_failed: true
118125
, href: "[email protected]:IonicaBizau/git-stats.git"
119126
}
120127
]
@@ -131,6 +138,7 @@ const INPUTS = [
131138
, hash: ""
132139
, search: ""
133140
, query: {}
141+
, parse_failed: true
134142
, href: "/path/to/file.png"
135143
}
136144
]
@@ -147,6 +155,7 @@ const INPUTS = [
147155
, hash: ""
148156
, search: ""
149157
, query: {}
158+
, parse_failed: true
150159
, href: "./path/to/file.png"
151160
}
152161
]
@@ -163,6 +172,7 @@ const INPUTS = [
163172
, hash: ""
164173
, search: ""
165174
, query: {}
175+
, parse_failed: true
166176
, href: "./.path/to/file.png"
167177
}
168178
]
@@ -179,6 +189,7 @@ const INPUTS = [
179189
, hash: ""
180190
, search: ""
181191
, query: {}
192+
, parse_failed: true
182193
, href: ".path/to/file.png"
183194
}
184195
]
@@ -195,6 +206,7 @@ const INPUTS = [
195206
, hash: ""
196207
, search: ""
197208
, query: {}
209+
, parse_failed: true
198210
, href: "path/to/file.png"
199211
}
200212
], [
@@ -210,6 +222,7 @@ const INPUTS = [
210222
, hash: ""
211223
, search: ""
212224
, query: {}
225+
, parse_failed: true
213226
, href: "[email protected]:9IonicaBizau/git-stats.git"
214227
}
215228
], [
@@ -225,6 +238,7 @@ const INPUTS = [
225238
, hash: ""
226239
, search: ""
227240
, query: {}
241+
, parse_failed: true
228242
, href: "[email protected]:0xABC/git-stats.git"
229243
}
230244
], [
@@ -241,6 +255,7 @@ const INPUTS = [
241255
, search: ""
242256
, href: "https://attacker.com/@example.com"
243257
, query: {}
258+
, parse_failed: false
244259
}
245260
], [
246261
"jav\r\nascript://%0aalert(1)"
@@ -255,6 +270,7 @@ const INPUTS = [
255270
, hash: ""
256271
, href: "javascript://%0aalert(1)"
257272
, query: {}
273+
, parse_failed: false
258274
, search: ""
259275
}
260276
], [
@@ -270,6 +286,7 @@ const INPUTS = [
270286
, hash: ""
271287
, href: "https://github.com:89/org/repo.git"
272288
, query: {}
289+
, parse_failed: false
273290
, search: ""
274291
}
275292
]

0 commit comments

Comments
 (0)