mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 12:05:05 +08:00
handle badly formatted index uid
This commit is contained in:
parent
40b3451a4e
commit
30dd790884
@ -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]
|
||||||
|
Loading…
Reference in New Issue
Block a user