refactor(engine): 增加最大操作数限制并优化变量解析逻辑
调整引擎的最大操作数限制从100,000到10,000,000以支持更复杂的表达式计算 优化变量解析逻辑,仅在明确以ctx[或ctx.开头时才进行表达式求值,其他情况保留原字符串 简化项目代码规范文档结构,保留核心规则并移除冗余内容
This commit is contained in:
@ -76,7 +76,7 @@ thread_local! {
|
||||
static RHIA_ENGINE: RefCell<Engine> = RefCell::new({
|
||||
let mut eng = Engine::new();
|
||||
// 限制执行步数,防止复杂表达式消耗过多计算资源
|
||||
eng.set_max_operations(100_000);
|
||||
eng.set_max_operations(10_000_000);
|
||||
// 严格变量模式,避免拼写错误导致静默为 null
|
||||
eng.set_strict_variables(true);
|
||||
// 注册常用工具函数
|
||||
|
||||
@ -54,8 +54,11 @@ fn resolve_assign_value(ctx: &Value, v: &Value) -> Value {
|
||||
return resolve_assign_value(ctx, &ref_json);
|
||||
}
|
||||
}
|
||||
// ctx[...] / ctx. 前缀 -> 表达式求值
|
||||
return eval_rhai_expr_json(s_trim, ctx).unwrap_or_else(|_| V::Null);
|
||||
// 仅当以 ctx[ 或 ctx. 前缀时才进行表达式求值;否则保留原字符串常量
|
||||
if s_trim.starts_with("ctx[") || s_trim.starts_with("ctx.") {
|
||||
return eval_rhai_expr_json(s_trim, ctx).unwrap_or_else(|_| V::Null);
|
||||
}
|
||||
return V::String(s.to_string());
|
||||
}
|
||||
v.get("content").cloned().unwrap_or(V::Null)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user