-
Notifications
You must be signed in to change notification settings - Fork 639
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
Filter block truncating content #576
Comments
I would expect the content within the If you didn't want that, you'd wrap the contents in a If it's really just being cut off entirely, that seems like a bug that should be fixed. |
I actually have the following test-case fail after updating nunjucks today, so I suspect there's something wrong indeed.
|
@carljm I actually tried wrapping my content in the raw tag as well which ended up giving me an empty string. It seems it is being truncated entirely. For example, @fabien Under parseFilterStatement, nunjucks is passing |
@fabien So you're saying this used to work, but broke at some point? Any chance you could bisect the commit that broke it? |
@carljm turns out I had implemented my own |
@fabien Ah! Well then, any chance you'd be willing to share your implementation with the community by submitting it as PR to fix the broken built-in version? :-) |
I'll look into it - IIRC I had my own filter for it. Then again, it might have been a fork of this one: |
I too am facing similar issue. My code is as follows
|
… The additional tests focus on template constructs within the filter block (`{% filter ... %}...{% endfilter %}` as introduced by mozilla#254): 1. variable evaluation inside filter block 2. block declaration inside filter block Both test are added to the list of `it('should handle filter blocks', ...`, which seems to be the project's convention for grouping tests by feature. Nonetheless, the two added test cases fail in different ways: 1. The variable expression test fails due to the discarding of any but the first token. Its output is unexpected. 2. The block declaration test fails due to a reference to undefined. It throws an error. Both issues are caused by the following line https://github.com/mozilla/nunjucks/blob/d4b3a07603b5a5c8adacb0c54aca53df8c931c73/src/parser.js#L1032. It can easily be seen that the given code comment is only true for text-only filter blocks.
@jrehwaldt That's an awesome contribution, thanks! It definitely looks like you've narrowed things down to the problematic assumption in the code. I think it's likely that with some study I (or someone else familiar with the internals) could give some useful guidance on how to approach the fix. Unfortunately I don't have time for that focused study today, or probably this week, but I'll put this at the top of my nunjucks list to get to when I can. Maybe someone else will be able to provide some useful feedback in the meantime. Thanks again! |
@carljm I remember diving into the internals a few months back when I first ran into this problem and found a possible culprit, but wasn't familiar enough with the Nunj internals to dive any deeper. Not sure if it's the actual culprit, but see my second comment:
Maybe that'll give you something to go off of when you find some time to look into this issue. |
@ElChupacabra26 Yeah, thanks for reminding me of that comment. That's actually the same observation @jrehwaldt makes in the linked tests PR. |
@carljm Ah yes, I see that now. Thanks |
* t576: Add test verifying that block-set can wrap a block. Fix filter block tag (fixes #576). Refactor this block of test assertions into separate tests. Adds *failing* tests illustrating both issues mentioned in #576. The additional tests focus on template constructs within the filter block (`{% filter ... %}...{% endfilter %}` as introduced by #254): 1. variable evaluation inside filter block 2. block declaration inside filter block
Fixed! Thanks @jrehwaldt for the failing test, and everyone for the investigation and pointers. |
* t576: Add test verifying that block-set can wrap a block. Fix filter block tag (fixes #576). Refactor this block of test assertions into separate tests. Adds *failing* tests illustrating both issues mentioned in #576. The additional tests focus on template constructs within the filter block (`{% filter ... %}...{% endfilter %}` as introduced by #254): 1. variable evaluation inside filter block 2. block declaration inside filter block
Thank you. Works perfectly. |
Thanks for the fix @carljm! |
Filter blocks with template info are getting chopped off at TOKEN_VARIABLE_START. What I'm trying to do is pass a template string to my filter, so I can do some processing before calling renderString() on the block contents. Something like this:
Is this the expected behavior and if so, is there another way of passing template data into a filter?
The text was updated successfully, but these errors were encountered: