Skip to content

Commit

Permalink
Add the parse_failed property.
Browse files Browse the repository at this point in the history
This will propagate the fact that the native parser failed to parse the input.
  • Loading branch information
IonicaBizau committed Aug 3, 2022
1 parent 3d1525d commit 4bae19e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const protocols = require("protocols")
* - `search` (String): The url querystring value (excluding `?`).
* - `href` (String): The normalized input url.
* - `query` (Object): The url querystring, parsed as object.
* - `parse_failed` (Boolean): Whether the parsing failed or not.
*/
function parsePath(url) {

Expand All @@ -37,6 +38,7 @@ function parsePath(url) {
, search: ""
, href: url
, query: {}
, parse_failed: false
}

try {
Expand Down Expand Up @@ -67,6 +69,7 @@ function parsePath(url) {
output.search = ""
output.href = url
output.query = {}
output.parse_failed = true
}

return output;
Expand Down
17 changes: 17 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const INPUTS = [
, search: ""
, href: "http://ionicabizau.net/blog"
, query: {}
, parse_failed: false
}
]
, [
Expand All @@ -34,6 +35,7 @@ const INPUTS = [
, search: ""
, href: "http://subdomain.ionicabizau.net/blog"
, query: {}
, parse_failed: false
}
]
, [
Expand All @@ -50,6 +52,7 @@ const INPUTS = [
, search: ""
, href: "http://ionicabizau.net/blog"
, query: {}
, parse_failed: false
}
]
, [
Expand All @@ -65,6 +68,7 @@ const INPUTS = [
, hash: "some-hash"
, search: "foo=bar&bar=42"
, query: { foo: "bar", bar: "42" }
, parse_failed: false
, href: "http://domain.com/path/name?foo=bar&bar=42#some-hash"
}
]
Expand All @@ -81,6 +85,7 @@ const INPUTS = [
, hash: "some-hash?foo=bar&bar=42"
, search: ""
, query: {}
, parse_failed: false
, href: "http://domain.com/path/name#some-hash?foo=bar&bar=42"
}
]
Expand All @@ -97,6 +102,7 @@ const INPUTS = [
, hash: ""
, search: ""
, query: {}
, parse_failed: false
, href: "git+ssh://git@host.xz/path/name.git"
}
]
Expand All @@ -115,6 +121,7 @@ const INPUTS = [
, hash: ""
, search: ""
, query: {}
, parse_failed: true
, href: "git@github.com:IonicaBizau/git-stats.git"
}
]
Expand All @@ -131,6 +138,7 @@ const INPUTS = [
, hash: ""
, search: ""
, query: {}
, parse_failed: true
, href: "/path/to/file.png"
}
]
Expand All @@ -147,6 +155,7 @@ const INPUTS = [
, hash: ""
, search: ""
, query: {}
, parse_failed: true
, href: "./path/to/file.png"
}
]
Expand All @@ -163,6 +172,7 @@ const INPUTS = [
, hash: ""
, search: ""
, query: {}
, parse_failed: true
, href: "./.path/to/file.png"
}
]
Expand All @@ -179,6 +189,7 @@ const INPUTS = [
, hash: ""
, search: ""
, query: {}
, parse_failed: true
, href: ".path/to/file.png"
}
]
Expand All @@ -195,6 +206,7 @@ const INPUTS = [
, hash: ""
, search: ""
, query: {}
, parse_failed: true
, href: "path/to/file.png"
}
], [
Expand All @@ -210,6 +222,7 @@ const INPUTS = [
, hash: ""
, search: ""
, query: {}
, parse_failed: true
, href: "git@github.com:9IonicaBizau/git-stats.git"
}
], [
Expand All @@ -225,6 +238,7 @@ const INPUTS = [
, hash: ""
, search: ""
, query: {}
, parse_failed: true
, href: "git@github.com:0xABC/git-stats.git"
}
], [
Expand All @@ -241,6 +255,7 @@ const INPUTS = [
, search: ""
, href: "https://attacker.com/@example.com"
, query: {}
, parse_failed: false
}
], [
"jav\r\nascript://%0aalert(1)"
Expand All @@ -255,6 +270,7 @@ const INPUTS = [
, hash: ""
, href: "javascript://%0aalert(1)"
, query: {}
, parse_failed: false
, search: ""
}
], [
Expand All @@ -270,6 +286,7 @@ const INPUTS = [
, hash: ""
, href: "https://github.com:89/org/repo.git"
, query: {}
, parse_failed: false
, search: ""
}
]
Expand Down

0 comments on commit 4bae19e

Please sign in to comment.