Convert if plugin to use jinja expressions instead of python eval.#1551
Convert if plugin to use jinja expressions instead of python eval.#1551gazpachoking merged 1 commit intonextfrom
Conversation
|
I'd sortof like to change the if plugin config to bring the expressions to the value side of a dict, so that we can validate it with a schema. We could add a custom schema 'format' for these expressions to catch syntax errors during validation. Not exactly sure what the nicest way to do that is, and if it's worth the extra validation ability though. if:
- if: year >= now.year
action: acceptIt sorta doubles up the 'if's, but it might also open room for an 'else': if:
- if: year >= now.year
action: accept
- elif: year < now.year - 2:
action: reject
- else:
action:
imdb:
min_score: 6.0Actually, I got stuck on the else bit. Is the implicit 'None' there horrible? I sorta think it is. |
|
I think the implicit None is fine, |
|
Awesome! I always told you eval is evil! :) |
|
I think we'll just go with the engine change for now. Config format can be revisited later. |
Motivation for changes:
Python eval is not safe for user input. Jinja expressions are much more appropriate.
Detailed changes:
ifplugin statements are now evaluated as jinja expressionsflexget.utils.evaluate_expressionwhich allows for lazy fields to stay lazy for evaluation. (which the fully default jinja method wouldn't do by itself)Our tests seem to just pass, not sure if there are cases where config changes could be needed.