-
Notifications
You must be signed in to change notification settings - Fork 171
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
Add validation mode #264
Add validation mode #264
Conversation
Codecov Report
@@ Coverage Diff @@
## master #264 +/- ##
============================================
+ Coverage 72.05% 72.25% +0.19%
- Complexity 1453 1468 +15
============================================
Files 231 231
Lines 4534 4563 +29
Branches 718 731 +13
============================================
+ Hits 3267 3297 +30
+ Misses 1014 1009 -5
- Partials 253 257 +4
Continue to review full report at Codecov.
|
Only issue I can think of is if a later expression becomes invalid due to not evaluating a macro or set tag. |
Any example you can think of? This only checks the syntax, not the expression values in validation mode. |
Yea just realized this was for syntax only which should be safe. |
} | ||
|
||
protected boolean evaluateIfElseTagNode(TagNode tagNode, JinjavaInterpreter interpreter) { | ||
if (tagNode.getName().equals(ElseTag.ELSE)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this checking hurting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's necessary anymore. isPositiveIfElseNode
is only called once at the top of the if
statement and again when an elseif
is encoutered.
return Objects.toString(interpreter.resolveELExpression(tagNode.getHelpers(), tagNode.getLineNumber()), ""); | ||
public String interpret(TagNode tagNode, JinjavaInterpreter interpreter) { | ||
String result = Objects.toString(interpreter.resolveELExpression(tagNode.getHelpers(), tagNode.getLineNumber()), ""); | ||
return interpreter.getContext().isValidationMode() ? result : ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the PrintTag
for ValidationMode
only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, it's a little-known tag.
{% print "hello" %}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems you return result only when isValidationMode()=true
. Or, I am missing something.
Will |
You're right. I need to do this for |
Currently jinjava only parses expressions inside active code paths. This is efficient, but also does not look at expressions that might have syntax errors.
This PR adds a validation mode to the interpreter that parses inactive code blocks for syntax, but does not set any variables nor actually execute any macros, functions or filters.
This allows full syntax checking of templates by calling
setValidationMode(true)
when building the context.