Make the compute_document_id validate the id

This commit is contained in:
Kerollmops 2020-05-18 15:18:23 +02:00
parent 2828b5fa19
commit d300d788c7
No known key found for this signature in database
GPG key ID: 92ADA4E935E71FA4
3 changed files with 17 additions and 36 deletions

View file

@ -3,12 +3,10 @@ use std::collections::{BTreeSet, HashSet};
use actix_web::{web, HttpResponse};
use actix_web_macros::{delete, get, post, put};
use indexmap::IndexMap;
use meilisearch_core::{update, Error};
use serde::Deserialize;
use serde_json::Value;
use meilisearch_core::{Error, serde::SerializerError};
use meilisearch_core::update;
use crate::error::ResponseError;
use crate::helpers::Authentication;
use crate::routes::{IndexParam, IndexUpdateResponse};
@ -45,11 +43,7 @@ async fn get_document(
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
if !update::validate_document_id(&path.document_id) {
return Err(Error::Serializer(SerializerError::InvalidDocumentIdFormat).into())
}
let document_id = update::compute_document_id(&path.document_id);
let document_id = update::compute_document_id(&path.document_id).map_err(Error::Serializer)?;
let reader = data.db.main_read_txn()?;
let response: Document = index
@ -72,11 +66,7 @@ async fn delete_document(
.open_index(&path.index_uid)
.ok_or(ResponseError::index_not_found(&path.index_uid))?;
if !update::validate_document_id(&path.document_id) {
return Err(Error::Serializer(SerializerError::InvalidDocumentIdFormat).into())
}
let document_id = update::compute_document_id(&path.document_id);
let document_id = update::compute_document_id(&path.document_id).map_err(Error::Serializer)?;
let mut update_writer = data.db.update_write_txn()?;
@ -248,11 +238,8 @@ async fn delete_documents(
let mut documents_deletion = index.documents_deletion();
for document_id in body.into_inner() {
let document_id_string = update::value_to_string(&document_id);
if !update::validate_document_id(&document_id_string) {
return Err(Error::Serializer(SerializerError::InvalidDocumentIdFormat).into())
}
let document_id = update::compute_document_id(document_id_string);
let document_id = update::value_to_string(&document_id);
let document_id = update::compute_document_id(&document_id).map_err(Error::Serializer)?;
documents_deletion.delete_document_by_id(document_id);
}