Make WordPress Core

Opened 3 years ago

Closed 19 months ago

#54013 closed defect (bug) (reported-upstream)

wp_restore_group_inner_container() causes duplicate inner container on content that already has an inner container

Reported by: davecpage's profile davecpage Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.8
Component: General Keywords: has-patch has-screenshots close
Focuses: Cc:

Description

I have a site that was originally authored in WP 5.7, when the group block added into the content an inner container div. The theme CSS relies upon this container to set an overall width from the parent.

When the site was upgraded to 5.8 we noticed that there were width issues on groups, and the reason why was due to a duplicate inner container. When attempting to edit the page in the editor the content was "fixed". We realised it was because the group block now removes the inner container from the HTML, with the function wp_restore_group_inner_container() restoring it if required.

The problem appears to be that the function will often "restore" the inner container even if it's already there. I eventually tracked it down to the initial regex used to detect if it's there. The regex appears to be more complex than required. The capturing of groups is unused for example. At the most simplest level, just changing the regex so that quantifiers are ungreedy causes it to no longer fail in a double adding way.

It was difficult to test on my local environment, but more consistant on our staging. I think because of the number of steps that the regex goes through. I can imagine different hosts having different limits for performance.

Simple PHP showing the modified regex on the same content https://3v4l.org/1s7cT

Originally added as https://github.com/WordPress/gutenberg/issues/34199

Attachments (5)

wp5.7-source.png (71.9 KB) - added by davecpage 3 years ago.
Editor source of content in 5.7 showing singular inner container
wp-5.8-frontend-source.png (29.7 KB) - added by davecpage 3 years ago.
Frontend source of same content within 5.8 showing double inner container
regex-before.png (60.9 KB) - added by davecpage 3 years ago.
Regex101 screenshot showing number of steps before change
regex-after-ungreedy.png (59.8 KB) - added by davecpage 3 years ago.
Regex101 screenshot showing number of steps after ungreedy change
54013.diff (749 bytes) - added by davecpage 3 years ago.
Adding ungreedy/lazy quantifier

Download all attachments as: .zip

Change History (7)

@davecpage
3 years ago

Editor source of content in 5.7 showing singular inner container

@davecpage
3 years ago

Frontend source of same content within 5.8 showing double inner container

@davecpage
3 years ago

Regex101 screenshot showing number of steps before change

@davecpage
3 years ago

Regex101 screenshot showing number of steps after ungreedy change

@davecpage
3 years ago

Adding ungreedy/lazy quantifier

#1 @davecpage
3 years ago

  • Keywords has-patch has-screenshots close added

Hi, not sure how this needs to close as the change has been implemented upstream as part of Gutenberg, see https://github.com/WordPress/gutenberg/issues/34199, which in itself has been backported into WordPress for 5.9

#2 @JeffPaul
19 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to reported-upstream
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.