Repository navigation
Read single-quoted attributes on RichText and other component tags - #195
Merged
dnnsjsk merged 1 commit intoNov 2, 2026
Merged
Conversation
Contributor
|
Merged and released in Blockstudio 7.7.11. The full CI and distribution checks passed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
<RichText attribute='title' tag='h2' />renders as an empty string, while the same tag with double quotes renders the value. The same applies to every attribute of a component tag written with single quotes or without quotes.Cause
Block::replace_custom_tag()parses the attributes of the tag with'/([a-zA-Z_][a-zA-Z0-9\-_:.]*)(?:\s*=\s*(?:"([^"]*)"|\'([^\']*)\'|([^ \/>]+)))?/'and then takes
$match[2] ?? ( $match[3] ?? ( $match[4] ?? true ) ). When group 3 or 4 matches,preg_match_all()fills the skipped group 2 with'', notnull, so??stops there.attributebecomes'', no value is resolved, and the tag is replaced with nothing. Fortag='h2'the element would be<p>.The other attribute parsers with the same pattern (
Block_Tags, the list renderer,Render_Document) already skip empty groups, so only this one is affected.Fix
PREG_UNMATCHED_AS_NULLon thatpreg_match_all()call. Unmatched groups arenull, the existing fallback reaches the group that matched. A matched empty value (class="") is still'', a bare attribute (useBlockProps) is stilltrue.Tests
BlockTest::test_replace_custom_tag_reads_single_quoted_attributesrenders the same RichText tag with double and single quotes and expects identical output. It fails before the change (single quotes give'') and passes after.tests/unit/block/BlockTest.phpruns green locally (63 tests) against a local WordPress; the full suites are left to CI as per AGENTS.md.