-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get rid of eval in rule's "then" clause #19
Comments
Interesting proposal indeed! I presume you suggest this for the TableRule's, right? Let's see. then/target action needs to support
What's your specific proposal how to make each of these safe? Are you thinking like a
I like that. Having options is good. |
I guess we can leave function calls for later, but really it may be quite simple, e.g.
where What do you think? |
I'm having second thoughts on this. Let say we want to allow function calls like this in then clauses:
how can we do this? |
How about adding a directive that imports modules into context, i.e.
Btw, I've had an idea that we could make rule syntax a bit simpler if we just use a dict like:
This way we exclude the situation where number of "then" and "target" clauses is mismatched. As for implementation, this would be compiled parse trees, something like:
Evaluating this is straightforward. Note that even if we don't use the dictionary and keep a separate "target" clause, we'll probably end up with the same approach to parsing. At least I can't understang how to write a solution based on the stuff you've written regarding A-expressions - seems to be to compicated to me. Using dictionaries like that has one important side effect - we don't know the order in wich then-clauses are executed. We should consider if that is a good thing or not. It may be easier to reason about rule's results if all statements in "then" clause would read from original context and write to a new one, rather than original - then the order of execution shouldn't matter. So "then" clauses would work like a transaction. Also we could consider changing keys and values in this dict, to force targets to be unique.
I'm not advocating a specific approach here, just sharing some ideas :-) |
that's a great idea. Never mind my
agree.
In terms of syntax, I like the second approach, it gets rid of the need for the target clause and is easy to understand:
|
With #15 almost ready, it makes sense to limit all rule's clauses to safe operations. If it's sufficient to leave only math operations and reading from variables, this can be done with a simple parser (should take no more than a day to implement and test).
Or we can keep supporting the old approach with eval and add the new safe mode - allowing rule engine to run unsafe mode only in certain cases (i.e. if all rules would be coming from trusted source).
The text was updated successfully, but these errors were encountered: