Skip to content

Commit 24befb0

Browse files
authored
Merge pull request #39 from afbase/afbase/aturi-validation-rsky-syntax
Afbase/aturi validation rsky syntax by @afbase
2 parents b3e9d6f + f6b8489 commit 24befb0

File tree

12 files changed

+1808
-186
lines changed

12 files changed

+1808
-186
lines changed

rsky-pds/src/repo/record/mod.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use futures::stream::{self, StreamExt};
1010
use lexicon_cid::Cid;
1111
use rsky_lexicon::com::atproto::admin::StatusAttr;
1212
use rsky_syntax::aturi::AtUri;
13+
use rsky_syntax::aturi_validation::ensure_valid_at_uri;
14+
use rsky_syntax::did::ensure_valid_did;
1315
use serde_json::Value as JsonValue;
1416
use std::env;
1517
use std::str::FromStr;
@@ -40,12 +42,16 @@ pub fn get_backlinks(uri: &AtUri, record: &RepoRecord) -> Result<Vec<models::Bac
4042
|| record_type == Ids::AppBskyGraphBlock.as_str()
4143
{
4244
if let Some(Lex::Ipld(Ipld::Json(JsonValue::String(subject)))) = record.get("subject") {
43-
// @TODO: Ensure valid DID https://github.com/bluesky-social/atproto/blob/main/packages/syntax/src/did.ts
44-
return Ok(vec![models::Backlink {
45-
uri: uri.to_string(),
46-
path: "subject".to_owned(),
47-
link_to: subject.clone(),
48-
}]);
45+
match ensure_valid_did(&uri) {
46+
Ok(_) => {
47+
return Ok(vec![models::Backlink {
48+
uri: uri.to_string(),
49+
path: "subject".to_owned(),
50+
link_to: subject.clone(),
51+
}])
52+
},
53+
Err(e) => bail!("get_backlinks Error: invalid did {}", e),
54+
};
4955
}
5056
} else if record_type == Ids::AppBskyFeedLike.as_str()
5157
|| record_type == Ids::AppBskyFeedRepost.as_str()
@@ -54,12 +60,15 @@ pub fn get_backlinks(uri: &AtUri, record: &RepoRecord) -> Result<Vec<models::Bac
5460
if let Some(Lex::Ipld(Ipld::Json(JsonValue::String(subject_uri)))) =
5561
ref_object.get("uri")
5662
{
57-
// TO DO: Ensure valid AT URI
58-
return Ok(vec![models::Backlink {
59-
uri: uri.to_string(),
60-
path: "subject.uri".to_owned(),
61-
link_to: subject_uri.clone(),
62-
}]);
63+
match ensure_valid_at_uri(&uri) {
64+
Ok(_) => {
65+
return Ok(vec![models::Backlink {
66+
uri: uri.to_string(),
67+
path: "subject.uri".to_owned(),
68+
link_to: subject_uri.clone(),
69+
}])},
70+
Err(e) => bail!("get_backlinks Error: invalid AtUri {}", e)
71+
};
6372
}
6473
}
6574
}

rsky-syntax/ATURI_VALIDATION.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Notes on AT-URI Validation
2+
3+
At the time of writing this, this rsky-syntax validation of AT-URI reflects the Typescript implementation of the [syntax package](https://github.com/bluesky-social/atproto/tree/main/packages/syntax) instead of the atproto.com [specification](https://atproto.com/specs/at-uri-scheme). There are some differences with the typescript and rust validation implementations and the specification for AT URIs:
4+
5+
- The validation conforms more to the "Full AT URI Syntax" form than the "Restricted AT URI Syntax" that is used in the [lexicon](https://github.com/bluesky-social/atproto/tree/main/packages/lexicon).
6+
- The Rust AT-URI validation does admit some invalid syntax.
7+
- The Rust DID and Handle validation adheres to the specification.
8+
- The Rust NSID and TID validation adheres to the specification.
9+
- The Rust Record Key validation adheres to the specification.
10+
11+
# References
12+
13+
1. [rsky-syntax PR](https://github.com/blacksky-algorithms/rsky/pull/39).

rsky-syntax/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ documentation = "https://docs.rs/rsky-syntax"
1212

1313
[dependencies]
1414
anyhow = "1.0.86"
15+
chrono = "0.4.39"
1516
lazy_static = "1.5.0"
1617
regex = "1.10.5"
1718
serde = { version = "1.0.160", features = ["derive"] }
1819
serde_derive = "^1.0"
1920
thiserror = "1.0.40"
20-
url = "2.5.2"
21+
url = "2.5.2"

0 commit comments

Comments
 (0)