From dfd20a39a7ddaea07103cac45d4d79bc7e6ce0d7 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Fri, 10 Apr 2026 16:42:35 +0000 Subject: fix: accept any d-tag identifier; percent-encode in URLs NIP-01 places no restriction on d tag characters and NIP-34 only recommends kebab-case without mandating it. Rejecting identifiers with whitespace or other URL-unsafe characters was therefore overly strict. The correct approach (per NIP-34 PR #2312 and GRASP-01) is to store identifiers verbatim on disk and percent-encode them when constructing URLs. The previous commit already handled the incoming direction (percent-decoding URL paths before filesystem lookup); this commit handles the outgoing direction and removes the validation restriction. Changes: - validate_identifier: drop whitespace rejection; only reject chars that are unsafe as filesystem directory names (/, \, null, . / ..) - git/mod.rs: add percent_encode() alongside percent_decode() - landing.rs: percent-encode identifier in nostr:// clone URL and gitworkshop link (also fixes a pre-existing bug where the clone URL displayed literal '{npub}' / '{identifier}' instead of the values) --- src/http/landing.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/http') diff --git a/src/http/landing.rs b/src/http/landing.rs index 5fc1e6e..042be5e 100644 --- a/src/http/landing.rs +++ b/src/http/landing.rs @@ -2,6 +2,7 @@ /// /// Generates HTML landing page for the Nostr relay. use crate::config::Config; +use crate::git::percent_encode; use crate::http::nip11::RelayInformationDocument; use std::collections::HashMap; @@ -847,7 +848,7 @@ pub fn get_repo_html(config: &Config, npub: &str, identifier: &str) -> String {
curl -Ls https://ngit.dev/install.sh | bash
-
git clone nostr://{{npub}}//{{identifier}}
+
git clone nostr://{npub}//{encoded_identifier}
@@ -867,7 +868,7 @@ pub fn get_repo_html(config: &Config, npub: &str, identifier: &str) -> String { // Construct gitworkshop link: gitworkshop.dev/npub/relayref/identifier const gitworkshopLink = document.getElementById('gitworkshop-link'); - gitworkshopLink.setAttribute('href', 'https://gitworkshop.dev/{npub}/' + relayref + '/{identifier}'); + gitworkshopLink.setAttribute('href', 'https://gitworkshop.dev/{npub}/' + relayref + '/{encoded_identifier}'); // Set footer domain var footerDomain = document.getElementById('footer-domain'); @@ -882,6 +883,7 @@ pub fn get_repo_html(config: &Config, npub: &str, identifier: &str) -> String { relay_name = config.relay_name(), npub = npub, identifier = identifier, + encoded_identifier = percent_encode(identifier), version = get_version(), theme_toggle = get_theme_toggle_html(), theme_script = get_theme_script(), -- cgit v1.2.3