handle badly formatted index uid

This commit is contained in:
mpostma 2021-03-11 22:23:48 +01:00
parent 40b3451a4e
commit 30dd790884
No known key found for this signature in database
GPG Key ID: CBC8A7C1D7A28C3A

View File

@ -72,10 +72,16 @@ impl<S: UuidStore> UuidResolverActor<S> {
} }
async fn handle_create(&self, name: String) -> Result<Uuid> { async fn handle_create(&self, name: String) -> Result<Uuid> {
if !is_index_uid_valid(&name) {
return Err(UuidError::BadlyFormatted(name))
}
self.store.create_uuid(name, true).await self.store.create_uuid(name, true).await
} }
async fn handle_get_or_create(&self, name: String) -> Result<Uuid> { async fn handle_get_or_create(&self, name: String) -> Result<Uuid> {
if !is_index_uid_valid(&name) {
return Err(UuidError::BadlyFormatted(name))
}
self.store.create_uuid(name, false).await self.store.create_uuid(name, false).await
} }
@ -99,6 +105,10 @@ impl<S: UuidStore> UuidResolverActor<S> {
} }
} }
fn is_index_uid_valid(uid: &str) -> bool {
uid.chars().all(|x| x.is_ascii_alphanumeric() || x == '-' || x == '_')
}
#[derive(Clone)] #[derive(Clone)]
pub struct UuidResolverHandle { pub struct UuidResolverHandle {
sender: mpsc::Sender<UuidResolveMsg>, sender: mpsc::Sender<UuidResolveMsg>,
@ -171,6 +181,8 @@ pub enum UuidError {
Heed(#[from] heed::Error), Heed(#[from] heed::Error),
#[error("Uuid error: {0}")] #[error("Uuid error: {0}")]
Uuid(#[from] uuid::Error), Uuid(#[from] uuid::Error),
#[error("Badly formatted index uid: {0}")]
BadlyFormatted(String),
} }
#[async_trait::async_trait] #[async_trait::async_trait]