fixing post table script
This commit is contained in:
@@ -220,6 +220,42 @@ impl MathValidator {
|
||||
}
|
||||
}
|
||||
|
||||
/// Valide script is not empty
|
||||
fn validate_script_basic_syntax(script: &str) -> Result<(), Status> {
|
||||
let trimmed = script.trim();
|
||||
|
||||
// Check for empty script
|
||||
if trimmed.is_empty() {
|
||||
return Err(Status::invalid_argument("Script cannot be empty"));
|
||||
}
|
||||
|
||||
// Basic parentheses balance check
|
||||
let mut paren_count = 0;
|
||||
for ch in trimmed.chars() {
|
||||
match ch {
|
||||
'(' => paren_count += 1,
|
||||
')' => {
|
||||
paren_count -= 1;
|
||||
if paren_count < 0 {
|
||||
return Err(Status::invalid_argument("Unbalanced parentheses: closing ')' without matching opening '('"));
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
if paren_count != 0 {
|
||||
return Err(Status::invalid_argument("Unbalanced parentheses: missing closing parentheses"));
|
||||
}
|
||||
|
||||
// Check for basic S-expression structure
|
||||
if !trimmed.starts_with('(') {
|
||||
return Err(Status::invalid_argument("Script must start with an opening parenthesis '('"));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Parse Steel script and extract column references used in mathematical contexts
|
||||
fn extract_math_column_references(script: &str) -> Result<Vec<(String, String)>, String> {
|
||||
let mut parser = Parser::new(script);
|
||||
@@ -554,6 +590,9 @@ pub async fn post_table_script(
|
||||
db_pool: &PgPool,
|
||||
request: PostTableScriptRequest,
|
||||
) -> Result<TableScriptResponse, Status> {
|
||||
// Basic script validation first
|
||||
validate_script_basic_syntax(&request.script)?;
|
||||
|
||||
// Start a transaction for ALL operations - critical for atomicity
|
||||
let mut tx = db_pool.begin().await
|
||||
.map_err(|e| Status::internal(format!("Failed to start transaction: {}", e)))?;
|
||||
|
||||
Reference in New Issue
Block a user