Skip to content

Commit

Permalink
fixed bug with url parsing; re: devx00
Browse files Browse the repository at this point in the history
  • Loading branch information
epi052 committed Nov 13, 2023
1 parent fe71f28 commit d805e46
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,13 @@ pub fn parse_url_with_raw_path(url: &str) -> Result<Url> {
bail!("url to parse has no authority and is therefore invalid");
}

// thanks to @devx00: the possibility exists for Url to return true for
// has_authority, but not have a host/port, so we'll check for that
// and bail if it's the case
if parsed.host().is_none() {
bail!("url to parse doesn't have a host");
}

// we have a valid url, the next step is to check the path and see if it's
// something that url::Url::parse would silently transform
//
Expand Down Expand Up @@ -729,6 +736,18 @@ mod tests {
use crate::config::Configuration;
use crate::scan_manager::{FeroxScans, ScanOrder};

#[test]
/// parse_url_with_raw_path with javascript:// should not throw an unimplemented! error
fn utils_parse_url_with_raw_path_javascript() {
let url = "javascript://";
let parsed = parse_url_with_raw_path(url);
assert!(parsed.is_err());
assert!(parsed
.unwrap_err()
.to_string()
.contains("url to parse doesn't have a host"));
}

#[test]
/// multiple tests for parse_url_with_raw_path
fn utils_parse_url_with_raw_path() {
Expand Down

0 comments on commit d805e46

Please sign in to comment.