Opened 8 weeks ago
Last modified 3 days ago
#64452 new defect (bug)
get_block_wrapper_attributes() function strips falsy values like zero
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Editor | Keywords: | has-patch has-unit-tests |
| Focuses: | Cc: |
Description
discovered while working on the Gutenberg project: https://github.com/WordPress/gutenberg/pull/74183#discussion_r2645807647
A zero value is a valid value for the id, class and aria-label attributes, but because the empty function is used, the value is unintentionally removed.
Steps to reproduce
- Crate a new post.
- Insert an Archive block.
- Open the Advanced panel and enter
0as the Additional CSS Class. - This will appear in the code editor:
<!-- wp:archives {"className":"0"} /--> - On the front end, open your browser developer tools and you'll see that the
classattribute is missing from that block.
Change History (6)
This ticket was mentioned in PR #10663 on WordPress/wordpress-develop by @wildworks.
8 weeks ago
#1
- Keywords has-patch has-unit-tests added
#2
@
8 weeks ago
- Keywords has-patch has-unit-tests removed
To achieve the ideal fix, the scope is a little larger than originally planned, but PR 10663 does the following:
- Move the
get_block_wrapper_attirbutes()function fromwp-includes/class-wp-block-supports.phptowp-includes/blocks.phpbecause it is unnatural for the function to be in a class file. - I noticed that there are no unit tests for the
get_block_wrapper_attirbutes()function itself. This time, I only tested the zero value, but maybe we should test attribute merging in the future. - Not only the
get_block_wrapper_attirbutes()function but alsoapply_block_support()method was corrected.
@wildworks commented on PR #10663:
7 weeks ago
#3
Thanks both for your reviews!
I thought it was odd to have the get_block_wrapper_attributes function in a class file, so I moved it to block.php, but it became harder to see what had changed 😅 For now, I'll revert the function to its original position.
@wildworks commented on PR #10663:
7 weeks ago
#4
Thanks to both of you for the reviews! Before making any changes to this PR, I'd like to double-check what values should be allowed for the attribute.
My understanding is as follows, but what do you think?
- ✅ Allow as valid value:
"0"(String)0(Integer) → Should be converted to a string"0"
- ❌ Don't allow as invalid value
true(boolean)false(boolean)nullarray()(array)
This ticket was mentioned in PR #10921 on WordPress/wordpress-develop by @wildworks.
3 days ago
#5
- Keywords has-patch has-unit-tests added
Trac ticket: https://core.trac.wordpress.org/ticket/64452
@wildworks commented on PR #10663:
3 days ago
#6
Oh, I re-forked the wordpress-develop repo and it seems all my submitted open PRs were closed 😂 I submitted a new PR that is equivalent to this one. https://github.com/WordPress/wordpress-develop/pull/10921
Trac ticket: https://core.trac.wordpress.org/ticket/64452