summaryrefslogtreecommitdiffstats
path: root/adenosine-cli
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2022-11-06 23:53:53 -0800
committerBryan Newbold <bnewbold@robocracy.org>2022-11-06 23:53:53 -0800
commit13b77ec75c5018f17048e2712ca83da3b4bb82dc (patch)
treeab56810a308f6ca8e676fae470b7a4e436c55ac9 /adenosine-cli
parente3739138455a178e656287d560e0dc793e230da1 (diff)
downloadadenosine-13b77ec75c5018f17048e2712ca83da3b4bb82dc.tar.gz
adenosine-13b77ec75c5018f17048e2712ca83da3b4bb82dc.zip
identifiers: allow trailing slashes in parts of at:// URIs
Diffstat (limited to 'adenosine-cli')
-rw-r--r--adenosine-cli/src/identifiers.rs14
1 files changed, 10 insertions, 4 deletions
diff --git a/adenosine-cli/src/identifiers.rs b/adenosine-cli/src/identifiers.rs
index 8a08ef3..ed9c0fd 100644
--- a/adenosine-cli/src/identifiers.rs
+++ b/adenosine-cli/src/identifiers.rs
@@ -81,14 +81,14 @@ impl FromStr for AtUri {
fn from_str(s: &str) -> Result<Self, Self::Err> {
lazy_static! {
- static ref ATURI_RE: Regex = Regex::new(r"^at://([a-zA-Z0-9:_\.-]+)(/([a-zA-Z0-9\.]+))?(/([a-zA-Z0-9\.-]+))?(#([a-zA-Z0-9/-]+))?$").unwrap();
+ static ref ATURI_RE: Regex = Regex::new(r"^at://([a-zA-Z0-9:_\.-]+)(/(([a-zA-Z0-9\.]+))?)?(/(([a-zA-Z0-9\.-]+))?)?(#([a-zA-Z0-9/-]+))?$").unwrap();
}
if let Some(caps) = ATURI_RE.captures(s) {
let uri = AtUri {
repository: DidOrHost::from_str(&caps[1])?,
- collection: caps.get(3).map(|v| v.as_str().to_string()),
- record: caps.get(5).map(|v| v.as_str().to_string()),
- fragment: caps.get(7).map(|v| v.as_str().to_string()),
+ collection: caps.get(4).map(|v| v.as_str().to_string()),
+ record: caps.get(7).map(|v| v.as_str().to_string()),
+ fragment: caps.get(9).map(|v| v.as_str().to_string()),
};
Ok(uri)
} else {
@@ -116,8 +116,10 @@ impl fmt::Display for AtUri {
#[test]
fn test_aturi() {
assert!(AtUri::from_str("at://bob.com").is_ok());
+ assert!(AtUri::from_str("at://bob.com/").is_ok());
assert!(AtUri::from_str("at://did:plc:bv6ggog3tya2z3vxsub7hnal").is_ok());
assert!(AtUri::from_str("at://bob.com/io.example.song").is_ok());
+ assert!(AtUri::from_str("at://bob.com/io.example.song/").is_ok());
assert!(AtUri::from_str("at://bob.com/io.example.song/3yI5-c1z-cc2p-1a").is_ok());
assert!(AtUri::from_str("at://bob.com/io.example.song/3yI5-c1z-cc2p-1a#/title").is_ok());
assert!(
@@ -143,6 +145,10 @@ fn test_aturi() {
assert_eq!(uri.collection, Some("io.example.song".to_string()));
assert_eq!(uri.record, Some("3yI5-c1z-cc2p-1a".to_string()));
assert_eq!(uri.fragment, Some("/title".to_string()));
+
+ let uri = AtUri::from_str("at://bob.com/io.example.song/").unwrap();
+ assert_eq!(uri.repository, DidOrHost::Host("bob.com".to_string()));
+ assert_eq!(uri.collection, Some("io.example.song".to_string()));
}
/// A String (newtype) representing an NSID