Skip to content
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

[bw_pages] - Infinite recursion processing post content #166

Open
bobbingwide opened this issue Nov 11, 2020 · 3 comments
Open

[bw_pages] - Infinite recursion processing post content #166

bobbingwide opened this issue Nov 11, 2020 · 3 comments
Assignees
Labels

Comments

@bobbingwide
Copy link
Owner

bobbingwide commented Nov 11, 2020

There's a new block in the Gutenberg plugin called post-content. I've discovered multiple ways of causing Gutenberg to go into an infinitely recursive loop. While trying to reason what the output should be when recursion is detected, I created a test case using the [bw_pages] shortcode which was equivalent to the scenario I'd tried using FSE. Two pages that would recursively embed each other ad infinitum.
Imagine my surprise when I discovered that my shortcode suffered the same problem.

Steps to reproduce

  1. Create two identical pages with the same shortcode. One called A, the other called C.
[bw_pages post_type=page format="T d e/C" post_parent=0 orderby=title numberposts=3]
  1. Create two other pages B and C - with normal content.
  2. Attempt to view either A or C.
  3. Wait a long time.

Details

In order to create a display that's a bit more understandable I decided it might be easier to
create 4 pages to be used in the test scenario.
A and C contain the problematic shortcode.
B and D are just for a bit of padding.

Page Content
A [bw_pages] shortcode
B plain content
C [bw_pages] shortcode
D plain content

Expected output

Note: Both [bw_pages] and core/post-content attempt to prevent the recursion by excluding themselves from the result set.
When the shortcode's format parameter doesn't include C - for Content - then the problem shouldn't occur.
Try this with E for Excerpt.

When viewing A, with format="T e / C" the processing should be:

  • A's content before the shortcode should be displayed
  • A runs [bw_pages] which returns B, C and D
  • B is formatted: Title edit and the rendered content
  • C is formatted: Title edit
    • And content is expanded. [bw_pages] returns A, B and D
    • A is formatted: Title edit
    • Recursion is detected
    • B is formatted as before
    • D is formatted
  • C's content after the shortcode is rendered
  • D is formatted

Here's the screen capture for A
image

And here's the screen capture for C
image

Additional notes
I added another line of code into the bw_pages() function that prevents double expansion of the top level post.

// Don't process the current post inside the loop
bw_process_this_post( $cp );
@bobbingwide bobbingwide self-assigned this Nov 11, 2020
@bobbingwide
Copy link
Owner Author

bobbingwide commented Nov 11, 2020

In order to make sense of the output I added class=A or class=C parameters to the shortcodes and the following custom CSS

div.A {background-color: #aaa;border: 1px solid grey;padding-left: 1em;}
div.C { background-color: #ccc;border: 1px dotted grey;padding-left: 2em; padding-bottom: 0.5em;}
ul.C, ul.A { display: block; list-style: none;}
.A li, .C li { margin-right: 5px; display: inline-block; }
body { font-size: 12px;}
p { margin: 2px}

Posts A and C also contained a bw_list shortcode, that creates the simple list of posts: eg B C D for A and A B D for C.

[bw_list post_type=page format="L e/C" post_parent=0 orderby=title numberposts=3 class=A]

@bobbingwide
Copy link
Owner Author

bobbingwide commented Nov 11, 2020

Scenario 3 - 3 pages with the same shortcode

The screenshots above showed the output when the queries were limited to 3 posts.

I added post E the similar to A and C,

Post bw_pages shortcode
A [bw_pages post_type=page format="L e/C" post_parent=0 orderby=title numberposts=4 class=A]
C [bw_pages post_type=page format="L e/C" post_parent=0 orderby=title numberposts=3 class=C]
E [bw_pages post_type=page format="T e/C" post_parent=0 orderby=title numberposts=5 class=E exclude=-1]

Results viewing E:
image

Note: Use of exclude=-1 on E means that its query returns itself.
In nested evaluation we see:

Content not available; already processed. post_content E (915) 915,867

The new function bw_report_recursion_error() provides additional information when WP_DEBUG is true.
eg post_content A (867) 915,867,872
where

  • post_content indicates this is the post_content field
  • A is the title of the post that's considered to have gone recursive
  • (867) is the post ID
  • 915,867,872 shows the current contents of the global $processed_posts

@bobbingwide
Copy link
Owner Author

We should still test what happens when the [bw_pages] shortcode is used in the Excerpt ( before more ) and the format= includes E for excerpt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant