🦠 The Definitive Gemini Protocol Toolkit
gemini gemini-protocol gemtext parser zero-dependency toolkit ast converter html markdown cli networking

fix(request): Handle invalid URLs

fuwn.net 51e79294 a63c3234

verified
+25 -4
+5 -2
src/request/blocking.rs
··· 44 44 .with_safe_defaults() 45 45 .with_custom_certificate_verifier(std::sync::Arc::new(GermVerifier::new())) 46 46 .with_no_client_auth(); 47 + let domain = url 48 + .domain() 49 + .ok_or_else(|| anyhow::anyhow!("Invalid URL: missing domain"))?; 47 50 let mut connection = rustls::ClientConnection::new( 48 51 std::sync::Arc::new(config), 49 - url.domain().unwrap_or("").try_into()?, 52 + domain.try_into()?, 50 53 )?; 51 54 let mut stream = std::net::TcpStream::connect(format!( 52 55 "{}:{}", 53 - url.domain().unwrap_or(""), 56 + domain, 54 57 url.port().unwrap_or(1965) 55 58 ))?; 56 59 let mut tls = rustls::Stream::new(&mut connection, &mut stream);
+8 -2
src/request/non_blocking.rs
··· 55 55 .with_no_client_auth(), 56 56 )) 57 57 .connect( 58 - rustls::ServerName::try_from(url.domain().unwrap_or_default())?, 58 + rustls::ServerName::try_from( 59 + url 60 + .domain() 61 + .ok_or_else(|| anyhow::anyhow!("Invalid URL: missing domain"))?, 62 + )?, 59 63 tokio::net::TcpStream::connect(format!( 60 64 "{}:{}", 61 - url.domain().unwrap_or(""), 65 + url 66 + .domain() 67 + .ok_or_else(|| anyhow::anyhow!("Invalid URL: missing domain"))?, 62 68 url.port().unwrap_or(1965) 63 69 )) 64 70 .await?,
+12
tests/status.rs
··· 29 29 fn i32_from_status() { 30 30 assert_eq!(i32::from(Status::Input), 10); 31 31 } 32 + 33 + #[cfg(feature = "blocking")] 34 + #[test] 35 + fn invalid_url_handling() { 36 + use url::Url; 37 + 38 + let invalid_url = Url::parse("gemini://").unwrap(); 39 + let result = germ::request::blocking::request(&invalid_url); 40 + 41 + assert!(result.is_err()); 42 + assert!(result.unwrap_err().to_string().contains("missing domain")); 43 + } 32 44 }