upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/lib/repo_ref.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2026-04-10 16:25:26 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2026-04-10 16:30:02 +0000
commit47622eb762e802a9caa2f37d8162eaaf2f9aa9ca (patch)
tree84afdf6b91aca8248a7cebdcc72ab5f782e847d8 /src/lib/repo_ref.rs
parent1978add2aa61a7e65655ec023d339e656402ad7b (diff)
fix: percent-encode identifier in nostr:// URLs and GRASP HTTP paths
Repository identifiers can contain any characters per NIP-01 d-tag rules. Encode them in nostr:// clone URLs (display and parse) and in GRASP /<npub>/<identifier>.git paths, aligning with NIP-34 and GRASP-01.
Diffstat (limited to 'src/lib/repo_ref.rs')
-rw-r--r--src/lib/repo_ref.rs8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/lib/repo_ref.rs b/src/lib/repo_ref.rs
index c0f9136..c4dd820 100644
--- a/src/lib/repo_ref.rs
+++ b/src/lib/repo_ref.rs
@@ -14,6 +14,7 @@ use nostr::{
14}; 14};
15use nostr_sdk::{Kind, NostrSigner, RelayUrl, Timestamp, Url}; 15use nostr_sdk::{Kind, NostrSigner, RelayUrl, Timestamp, Url};
16use serde::{Deserialize, Serialize}; 16use serde::{Deserialize, Serialize};
17use urlencoding::encode as pct_encode;
17 18
18#[cfg(not(test))] 19#[cfg(not(test))]
19use crate::client::Client; 20use crate::client::Client;
@@ -661,7 +662,7 @@ pub fn detect_existing_grasp_servers(
661 } 662 }
662 663
663 let clone_url_is_grasp_server_format = if let Ok(npub) = extract_npub(url) { 664 let clone_url_is_grasp_server_format = if let Ok(npub) = extract_npub(url) {
664 url.contains(&format!("/{npub}/{identifier}.git")) 665 url.contains(&format!("/{npub}/{}.git", pct_encode(identifier)))
665 } else { 666 } else {
666 false 667 false
667 }; 668 };
@@ -809,8 +810,9 @@ pub fn format_grasp_server_url_as_clone_url(
809 "https://" 810 "https://"
810 }; 811 };
811 Ok(format!( 812 Ok(format!(
812 "{prefix}{grasp_server_url}/{}/{identifier}.git", 813 "{prefix}{grasp_server_url}/{}/{}.git",
813 public_key.to_bech32()? 814 public_key.to_bech32()?,
815 pct_encode(identifier)
814 )) 816 ))
815} 817}
816 818