mirror of
https://github.com/rustmailer/bichon.git
synced 2026-08-03 07:48:34 +02:00
add regex pattern validation via DuckDB
This commit is contained in:
@@ -99,6 +99,21 @@ impl DuckDBManager {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn validate_regex(&self, pattern: &str) -> BichonResult<()> {
|
||||||
|
let conn = self.conn()?;
|
||||||
|
let check_sql = "SELECT regexp_matches('', ?)";
|
||||||
|
if let Err(e) = conn
|
||||||
|
.prepare(check_sql)
|
||||||
|
.and_then(|mut stmt| stmt.execute([pattern]))
|
||||||
|
{
|
||||||
|
return Err(raise_error!(
|
||||||
|
format!("Invalid Regular Expression for DuckDB: {}", e).into(),
|
||||||
|
ErrorCode::InvalidParameter
|
||||||
|
));
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn delete_envelopes_by_account(&self, account_id: u64) -> BichonResult<usize> {
|
pub fn delete_envelopes_by_account(&self, account_id: u64) -> BichonResult<usize> {
|
||||||
let mut conn = self.conn()?;
|
let mut conn = self.conn()?;
|
||||||
let tx = conn
|
let tx = conn
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
modules::{
|
modules::{
|
||||||
|
duckdb::init::duckdb,
|
||||||
error::{code::ErrorCode, BichonResult},
|
error::{code::ErrorCode, BichonResult},
|
||||||
indexer::{envelope::Envelope, manager::ENVELOPE_INDEX_MANAGER},
|
indexer::{envelope::Envelope, manager::ENVELOPE_INDEX_MANAGER},
|
||||||
rest::response::DataPage,
|
rest::response::DataPage,
|
||||||
@@ -78,6 +79,17 @@ impl SearchRequest {
|
|||||||
ErrorCode::InvalidParameter
|
ErrorCode::InvalidParameter
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(ref pattern) = self.filter.text {
|
||||||
|
if let Err(_) = duckdb()?.validate_regex(pattern) {
|
||||||
|
return Err(raise_error!(
|
||||||
|
"Invalid search pattern: The regular expression is not supported by DuckDB."
|
||||||
|
.into(),
|
||||||
|
ErrorCode::InvalidParameter
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user