Closed (fixed)
Project:
Entity Embed
Version:
8.x-1.x-dev
Component:
Code
Priority:
Critical
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
21 Jun 2019 at 21:25 UTC
Updated:
12 Jul 2019 at 02:06 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
wim leersQuoting myself from #3052482-130: Expand EntityEmbedFilter's test coverage: test many more edge cases, change to kernel test:
Next: patch.
Comment #3
wim leersJust landed #3052482: Expand EntityEmbedFilter's test coverage: test many more edge cases, change to kernel test.
Let's add a failing test first.
Comment #4
wim leersHere's a fix, that ports the exact same pattern that #2073753: Fix and add tests for the recursive rendering protection of the 'Rendered entity' formatter introduced — I'm glad we can follow an existing pattern 🙏
Comment #6
wim leers#4 made the minimal changes necessary; we should also port the use of the logger from #2073753: Fix and add tests for the recursive rendering protection of the 'Rendered entity' formatter.
Comment #7
wim leersNow the tricky
try … catchstructure can just disappear! That has been known to cause problems (see #3055050: Loosen EntityEmbedFilter's greedy exception capture: catch only relevant exceptions).Comment #8
wim leersThis is probably ready, but I'm not gonna commit it right away, I wanna look at it with a fresh set of eyes prior to committing.
Comment #9
oknateI must be missing something, but I don't see how testRecursionProtection tests for recursion, rather than just the number of times the entity is rendered through the filter.
I was thinking that recursion would be making sure if Node 1 embeds node 2 and node 2 embeds node 1, that it would prevent it from blowing up the site, by endlessly rendering the same entities that self-reference.
But this just tests that you don't render the same entity more than 20 times on a page, right?
I guess it's a simple solution for the more complex problem. Because there shouldn't be a real world situation where someone adds the same embed code 21 times in a body field.
Part of me thinks that it's cheating, as you're not allowing for "other use cases" other than recursive rendering. But it does make the solution much simpler. It would be hard to track if the rendering was done in a parent entity, especially with entity embed. It's been in core for a while and no one complains they can't reference the same entity in the same context node 21 times on a parent. So I it seems to be a nice solution.
Perhaps, we should have another test, not necessarily a Kernel test, where it's actually this:
Comment #10
wim leersYou're not missing something, you're exactly right!
See #2073753: Fix and add tests for the recursive rendering protection of the 'Rendered entity' formatter for why this approach was chosen in Drupal core, because Drupal 8's render caching meant that the function call stack based recursion detection broke.
The goal is not to perfectly detect recursion (which never makes sense anyway, and core also doesn't manage to detect this reliably). The goal is to not let this crash a site.
Comment #11
wim leersThat being said, I think it'd be reasonable to add a functional test with a node embedding itself in the "full" display mode using the Entity Embed filter in the body field. Then accessing
/node/NIDshould assert that the entity label is present precisely 21 times (the recursion limit in the filter plus the original rendered entity).I'll do that on Monday (or perhaps tomorrow), unless you want to :)
Comment #12
oknateAdding functional test, and one coding standard fix:
-use Drupal\entity_embed\Exception\RecursiveRenderingException;Comment #13
oknateMinor cleanup.
Comment #14
wim leersFixing nits and the sole remaining coding standard: the one I introduced!
Comment #16
wim leers🚢
Comment #17
oknateSweet!
Comment #19
tom.moffett commentedThis change caused the same issue seen here, https://www.drupal.org/project/drupal/issues/2940605, now with embedded entities.
Comment #20
oknateTom, can you create a separate issue for it, so this one doesn’t get too long?
Comment #21
tom.moffett commentedSure, I created this issue:
https://www.drupal.org/project/entity_embed/issues/3067452