From 317092b717ebfefdd0b69b2c5e877d543c50c2e3 Mon Sep 17 00:00:00 2001 From: Joshua Thijssen Date: Sat, 8 Feb 2025 19:02:27 +0100 Subject: [PATCH] Error on incorrect proxy URI --- CHANGELOG.md | 1 + src/proxy.rs | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3424c019..18438925 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/proxy.rs b/src/proxy.rs index e0dfb340..12ed506a 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -84,7 +84,7 @@ impl Proxy { } fn new_with_flag(proxy: &str, from_env: bool) -> Result { - let mut uri = proxy.parse::().unwrap(); + let mut uri = proxy.parse::().or(Err(Error::InvalidProxyUrl))?; // The uri must have an authority part (with the host), or // it is invalid. @@ -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()); + } }