From 83448a99aaf18c7a045a081c5de0c22bc4a83de1 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Wed, 27 Nov 2024 17:08:25 +0000 Subject: chore: bump rust-nosrt v0.37.0 use RelayUrl in repo_ref which I had resisted as it mutates relay urls when printed to append a slash --- src/lib/git/nostr_url.rs | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'src/lib/git/nostr_url.rs') diff --git a/src/lib/git/nostr_url.rs b/src/lib/git/nostr_url.rs index b310782..e4b6825 100644 --- a/src/lib/git/nostr_url.rs +++ b/src/lib/git/nostr_url.rs @@ -3,7 +3,7 @@ use std::{collections::HashSet, str::FromStr}; use anyhow::{anyhow, bail, Context, Error, Result}; use nostr::nips::nip01::Coordinate; -use nostr_sdk::{PublicKey, Url}; +use nostr_sdk::{PublicKey, RelayUrl, Url}; #[derive(Debug, PartialEq, Default, Clone)] pub enum ServerProtocol { @@ -85,8 +85,8 @@ impl std::str::FromStr for NostrUrlDecoded { decoded = format!("wss://{decoded}"); } let url = - Url::parse(&decoded).context("could not parse relays in nostr git url")?; - relays.push(url.to_string()); + RelayUrl::parse(&decoded).context("could not parse relays in nostr git url")?; + relays.push(url); } else if name == "protocol" { protocol = match value.as_ref() { "ssh" => Some(ServerProtocol::Ssh), @@ -151,8 +151,8 @@ impl std::str::FromStr for NostrUrlDecoded { decoded = format!("wss://{decoded}"); } let url = - Url::parse(&decoded).context("could not parse relays in nostr git url")?; - relays.push(url.to_string()); + RelayUrl::parse(&decoded).context("could not parse relays in nostr git url")?; + relays.push(url); } coordinates.insert(Coordinate { identifier, @@ -852,7 +852,7 @@ mod tests { .unwrap(), kind: nostr_sdk::Kind::GitRepoAnnouncement, relays: if relays { - vec!["wss://nos.lol/".to_string()] + vec![RelayUrl::parse("wss://nos.lol").unwrap()] } else { vec![] }, @@ -873,7 +873,8 @@ mod tests { ) .unwrap(), kind: nostr_sdk::Kind::GitRepoAnnouncement, - relays: vec!["wss://nos.lol".to_string()], // wont add the slash + relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()], /* wont add the + * slash */ }]), protocol: None, user: None, @@ -942,8 +943,8 @@ mod tests { fn with_multiple_encoded_relays() -> Result<()> { let url = format!( "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit?relay={}&relay1={}", - urlencoding::encode("wss://nos.lol"), - urlencoding::encode("wss://relay.damus.io"), + urlencoding::encode("wss://nos.lol/"), + urlencoding::encode("wss://relay.damus.io/"), ); assert_eq!( NostrUrlDecoded::from_str(&url)?, @@ -957,8 +958,8 @@ mod tests { .unwrap(), kind: nostr_sdk::Kind::GitRepoAnnouncement, relays: vec![ - "wss://nos.lol/".to_string(), - "wss://relay.damus.io/".to_string(), + RelayUrl::parse("wss://nos.lol/").unwrap(), + RelayUrl::parse("wss://relay.damus.io/").unwrap(), ], }]), protocol: None, @@ -1039,8 +1040,8 @@ mod tests { fn with_multiple_encoded_relays() -> Result<()> { let url = format!( "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/{}/{}/ngit", - urlencoding::encode("wss://nos.lol"), - urlencoding::encode("wss://relay.damus.io"), + urlencoding::encode("wss://nos.lol/"), + urlencoding::encode("wss://relay.damus.io/"), ); assert_eq!( NostrUrlDecoded::from_str(&url)?, @@ -1054,8 +1055,8 @@ mod tests { .unwrap(), kind: nostr_sdk::Kind::GitRepoAnnouncement, relays: vec![ - "wss://nos.lol/".to_string(), - "wss://relay.damus.io/".to_string(), + RelayUrl::parse("wss://nos.lol/").unwrap(), + RelayUrl::parse("wss://relay.damus.io/").unwrap(), ], }]), protocol: None, -- cgit v1.2.3