Opened 9 hours ago
Last modified 9 hours ago
#65379 new defect (bug)
Elements: Guard against non-string className in render filter
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | 7.1 | Priority: | normal |
| Severity: | normal | Version: | trunk |
| Component: | Editor | Keywords: | gutenberg-merge has-patch has-unit-tests |
| Focuses: | Cc: |
Description
This ticket tracks the backport of PHP files for the following Gutenberg update:
https://github.com/WordPress/gutenberg/pull/78841
Adds a safeguard in elements block support rendering to prevent fatal errors when a block’s className attribute is not a string. The backport updates wp_render_elements_class_name() to bail early and return block content unchanged for invalid className values, and includes a PHPUnit test covering this regression case.
Change History (1)
This ticket was mentioned in PR #12028 on WordPress/wordpress-develop by @aaronrobertshaw.
9 hours ago
#1
- Keywords has-patch has-unit-tests added
Note: See
TracTickets for help on using
tickets.
Trac ticket: https://core.trac.wordpress.org/ticket/65379
This PR brings the changes from the following Gutenberg PR to core:
WordPress/gutenberg#78841
## Description
Hardens the elements block support render filter against invalid block attribute data.
wp_render_elements_class_name()currently readsattrs.classNameand passes it intopreg_match(). WhileclassNameis expected to be astring, malformed or corrupted stored block data can contain other types (for example, anarray), which can trigger a fatalTypeErrorin PHP 8+.This backport adds a defensive type check so that when
classNameis not a string, the function returns the original block content unchanged instead of attempting regex matching.A regression test is also added to ensure non-string
classNamevalues do not cause fatals and continue to fail gracefully.## Testing
wpRenderElementsSupport.phptest_elements_block_support_class_with_non_string_class_name