mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-09 22:48:54 +01:00
Check the Rhai syntax before accepting the script
This commit is contained in:
parent
2d97164d9f
commit
45af18ae9c
@ -599,6 +599,11 @@ pub async fn edit_documents_by_function(
|
|||||||
|
|
||||||
// analytics.delete_documents(DocumentDeletionKind::PerFilter, &req);
|
// analytics.delete_documents(DocumentDeletionKind::PerFilter, &req);
|
||||||
|
|
||||||
|
let engine = milli::rhai::Engine::new();
|
||||||
|
if let Err(e) = engine.compile(&function) {
|
||||||
|
return Err(ResponseError::from_msg(e.to_string(), Code::BadRequest));
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(ref filter) = filter {
|
if let Some(ref filter) = filter {
|
||||||
// we ensure the filter is well formed before enqueuing it
|
// we ensure the filter is well formed before enqueuing it
|
||||||
|| -> Result<_, ResponseError> {
|
|| -> Result<_, ResponseError> {
|
||||||
|
@ -45,7 +45,7 @@ pub use search::new::{
|
|||||||
};
|
};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
pub use thread_pool_no_abort::{PanicCatched, ThreadPoolNoAbort, ThreadPoolNoAbortBuilder};
|
pub use thread_pool_no_abort::{PanicCatched, ThreadPoolNoAbort, ThreadPoolNoAbortBuilder};
|
||||||
pub use {charabia as tokenizer, heed};
|
pub use {charabia as tokenizer, heed, rhai};
|
||||||
|
|
||||||
pub use self::asc_desc::{AscDesc, AscDescError, Member, SortError};
|
pub use self::asc_desc::{AscDesc, AscDescError, Member, SortError};
|
||||||
pub use self::criterion::{default_criteria, Criterion, CriterionError};
|
pub use self::criterion::{default_criteria, Criterion, CriterionError};
|
||||||
|
@ -16,7 +16,7 @@ use grenad::{Merger, MergerBuilder};
|
|||||||
use heed::types::Str;
|
use heed::types::Str;
|
||||||
use heed::Database;
|
use heed::Database;
|
||||||
use rand::SeedableRng;
|
use rand::SeedableRng;
|
||||||
use rhai::{Engine, Scope};
|
use rhai::{Dynamic, Engine, Scope};
|
||||||
use roaring::RoaringBitmap;
|
use roaring::RoaringBitmap;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use slice_group_by::GroupBy;
|
use slice_group_by::GroupBy;
|
||||||
@ -239,11 +239,13 @@ where
|
|||||||
let mut scope = Scope::new();
|
let mut scope = Scope::new();
|
||||||
scope.push("doc", document);
|
scope.push("doc", document);
|
||||||
|
|
||||||
let new_document = engine.eval_ast_with_scope::<rhai::Map>(&mut scope, &ast).unwrap();
|
let _ = engine.eval_ast_with_scope::<Dynamic>(&mut scope, &ast).unwrap();
|
||||||
|
let new_document = scope.remove("doc").unwrap();
|
||||||
let new_document = rhaimap_to_object(new_document);
|
let new_document = rhaimap_to_object(new_document);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
document_id, new_document[primary_key],
|
Some(&document_id),
|
||||||
|
new_document.get(primary_key),
|
||||||
"you cannot change the document id when editing documents"
|
"you cannot change the document id when editing documents"
|
||||||
);
|
);
|
||||||
documents_batch_builder.append_json_object(&new_document)?;
|
documents_batch_builder.append_json_object(&new_document)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user