tangled
alpha
login
or
join now
fuwn.net
/
germ
0
fork
atom
🦠 The Definitive Gemini Protocol Toolkit
gemini
gemini-protocol
gemtext
parser
zero-dependency
toolkit
ast
converter
html
markdown
cli
networking
0
fork
atom
overview
issues
pulls
pipelines
fix(request): Handle invalid URLs
fuwn.net
6 months ago
51e79294
a63c3234
verified
This commit was signed with the committer's
known signature
.
fuwn.net
SSH Key Fingerprint:
SHA256:VPdFPyPbd6JkoMyWUdZ/kkTcIAt3sxjXD2XSAZ7FYC4=
+25
-4
3 changed files
expand all
collapse all
unified
split
src
request
blocking.rs
non_blocking.rs
tests
status.rs
+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
47
+
let domain = url
48
48
+
.domain()
49
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
49
-
url.domain().unwrap_or("").try_into()?,
52
52
+
domain.try_into()?,
50
53
)?;
51
54
let mut stream = std::net::TcpStream::connect(format!(
52
55
"{}:{}",
53
53
-
url.domain().unwrap_or(""),
56
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
58
-
rustls::ServerName::try_from(url.domain().unwrap_or_default())?,
58
58
+
rustls::ServerName::try_from(
59
59
+
url
60
60
+
.domain()
61
61
+
.ok_or_else(|| anyhow::anyhow!("Invalid URL: missing domain"))?,
62
62
+
)?,
59
63
tokio::net::TcpStream::connect(format!(
60
64
"{}:{}",
61
61
-
url.domain().unwrap_or(""),
65
65
+
url
66
66
+
.domain()
67
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
32
+
33
33
+
#[cfg(feature = "blocking")]
34
34
+
#[test]
35
35
+
fn invalid_url_handling() {
36
36
+
use url::Url;
37
37
+
38
38
+
let invalid_url = Url::parse("gemini://").unwrap();
39
39
+
let result = germ::request::blocking::request(&invalid_url);
40
40
+
41
41
+
assert!(result.is_err());
42
42
+
assert!(result.unwrap_err().to_string().contains("missing domain"));
43
43
+
}
32
44
}