WordPress.org

Make WordPress Core

Opened 7 weeks ago

#54013 new defect (bug)

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

Reported by: davecpage Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.8
Component: General Keywords:
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 7 weeks ago.
Editor source of content in 5.7 showing singular inner container
wp-5.8-frontend-source.png (29.7 KB) - added by davecpage 7 weeks ago.
Frontend source of same content within 5.8 showing double inner container
regex-before.png (60.9 KB) - added by davecpage 7 weeks ago.
Regex101 screenshot showing number of steps before change
regex-after-ungreedy.png (59.8 KB) - added by davecpage 7 weeks ago.
Regex101 screenshot showing number of steps after ungreedy change
54013.diff (749 bytes) - added by davecpage 7 weeks ago.
Adding ungreedy/lazy quantifier

Download all attachments as: .zip

Change History (5)

@davecpage
7 weeks ago

Editor source of content in 5.7 showing singular inner container

@davecpage
7 weeks ago

Frontend source of same content within 5.8 showing double inner container

@davecpage
7 weeks ago

Regex101 screenshot showing number of steps before change

@davecpage
7 weeks ago

Regex101 screenshot showing number of steps after ungreedy change

@davecpage
7 weeks ago

Adding ungreedy/lazy quantifier

Note: See TracTickets for help on using tickets.