Skip to content

Commit

Permalink
Error on incorrect proxy URI
Browse files Browse the repository at this point in the history
  • Loading branch information
jaytaph authored and algesten committed Feb 8, 2025
1 parent 8b46d37 commit 317092b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Unreleased

* Fix panic when parsing malformed proxy URI (#990)
* ureq::Error wrapped as io::Error should pass through body chain (#984)
* send_json should set content-length header (#983)

Expand Down
14 changes: 13 additions & 1 deletion src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Proxy {
}

fn new_with_flag(proxy: &str, from_env: bool) -> Result<Self, Error> {
let mut uri = proxy.parse::<Uri>().unwrap();
let mut uri = proxy.parse::<Uri>().or(Err(Error::InvalidProxyUrl))?;

// The uri must have an authority part (with the host), or
// it is invalid.
Expand Down Expand Up @@ -469,4 +469,16 @@ mod test {
assert_eq!(c.proto(), Proto::Http);
assert_eq!(c.uri(), "http://localhost:1234");
}

#[test]
fn proxy_empty_env_url() {
let result = Proxy::new_with_flag("", false);
assert!(result.is_err());
}

#[test]
fn proxy_invalid_env_url() {
let result = Proxy::new_with_flag("r32/?//52:**", false);
assert!(result.is_err());
}
}

0 comments on commit 317092b

Please sign in to comment.