More Url validation

This commit is contained in:
Mike Dilger 2022-12-26 11:48:08 +13:00
parent 5255d33fdd
commit 3795034b1e
2 changed files with 7 additions and 2 deletions

View File

@ -155,7 +155,7 @@ impl DbRelay {
// Get from 'e' and 'p' tags // Get from 'e' and 'p' tags
let sql = let sql =
"INSERT OR IGNORE INTO RELAY (url, rank) SELECT DISTINCT field1, 3 FROM event_tag where (label='e' OR label='p') and field1 like 'wss%'"; "INSERT OR IGNORE INTO RELAY (url, rank) SELECT DISTINCT field1, 3 FROM event_tag where (label='e' OR label='p') and field1 like 'ws%://%'";
spawn_blocking(move || { spawn_blocking(move || {
let maybe_db = GLOBALS.db.blocking_lock(); let maybe_db = GLOBALS.db.blocking_lock();

View File

@ -128,7 +128,9 @@ impl Globals {
.entry(id) .entry(id)
.and_modify(|urls| { .and_modify(|urls| {
if let Some(ref u) = url { if let Some(ref u) = url {
urls.push(u.to_owned()); if let Ok(valid) = Url::new_validated(u) {
urls.push(valid);
}
} }
}) })
.or_insert_with(|| if let Some(u) = url { vec![u] } else { vec![] }); .or_insert_with(|| if let Some(u) = url { vec![u] } else { vec![] });
@ -223,6 +225,9 @@ pub async fn followed_pubkeys() -> Vec<PublicKeyHex> {
pub async fn follow_key_and_relay(pubkey: String, relay: String) -> Result<DbPerson, String> { pub async fn follow_key_and_relay(pubkey: String, relay: String) -> Result<DbPerson, String> {
let pubkeyhex = PublicKeyHex(pubkey.clone()); let pubkeyhex = PublicKeyHex(pubkey.clone());
// Validate the url
let _ = Url::new_validated(&relay).map_err(|e| format!("{}", e))?;
// Create or update them // Create or update them
let person = match DbPerson::fetch_one(pubkeyhex.clone()) let person = match DbPerson::fetch_one(pubkeyhex.clone())
.await .await