defer variables containing deferred vals & track deferred nodes in context#327
Merged
Conversation
Codecov Report
@@ Coverage Diff @@
## master #327 +/- ##
============================================
+ Coverage 71.47% 71.49% +0.02%
- Complexity 1572 1575 +3
============================================
Files 239 239
Lines 4939 4954 +15
Branches 797 799 +2
============================================
+ Hits 3530 3542 +12
- Misses 1124 1126 +2
- Partials 285 286 +1
Continue to review full report at Codecov.
|
boulter
requested changes
Apr 30, 2019
84be45e to
e5db0b4
Compare
e5db0b4 to
43a36ab
Compare
pfarrel
reviewed
May 3, 2019
| interpreter.getContext().put(var, interpreter.resolveELExpression(expr, tagNode.getLineNumber())); | ||
| } | ||
| } catch (DeferredValueException e) { | ||
| Stream.of(varTokens).forEach(varToken -> interpreter.getContext().put(varToken.trim(), DeferredValue.instance())); |
Contributor
There was a problem hiding this comment.
This is the key bit that makes "deferred-ness" infectious, for any other readers trying to see what actually changed through the whitespace diff.
2a99110 to
4cc4a12
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Following #282
It's possible that variables contain deferred values, in that case the assigned variable(s) should be deferred too, since expressions depending on variables containing deferred values can't and shouldn't be evaluated & rendered.
Example:
Input:
Render before the change:
After the change:
We need some way of tracking which nodes were deferred so that we can escape them before post-processing the rendered template with Jsoup. If Jsoup encounters these kinds of tags in a place where no characters are allowed it changes the template and even ignores following tags inside of that tag.
Example:
Input:
Jsoup output:
In order to escape these tags properly we need to know which tags were deferred.
We also want to handle the case where a deferred tag contains not-deferred variables. We need to be able to take these out of the context later for further processing.
Example:
Input:
Output:
defined_vardisappears butsome_varwill not be rendered since it contains a deferred value. If we know which tags have been deferred after the render we can take the vars out of the context and pass them along for a second render.Considerations: I've tried a couple of different approaches, including partial evaluation and extracting variables of deferred tags. Both are a lot more complex than I initially thought and too specific to our use-case, especially given the fact that we don't own
ExpressionFactoryImpland all the code that this class depends on. IMO this is the most flexible solution, since users can decide what to do with the deferred nodes after rendering is done.