Repository navigation
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
`get_attribute_names_with_prefix()` flushes enqueued `add_class()` and `remove_class()` calls only when they could add or remove the `class` attribute. It decided whether the tag has a `class` attribute from the input document alone and ignored an enqueued `set_attribute()` or `remove_attribute()` for `class`, so two kinds of sequence gave the wrong answer: - The input has a `class` attribute, `remove_attribute( 'class' )` or `set_attribute( 'class', false )` enqueues its removal, and `add_class()` follows. The method did not flush, found the removal, and omitted `class`, while `get_updated_html()` produces a `class` attribute. - The input has no `class` attribute, `set_attribute( 'class', ... )` enqueues one, and `remove_class()` removes every class in it. The method did not flush, found the addition, and reported `class`, while `get_updated_html()` produces no `class` attribute. The method now uses the enqueued `class` attribute update, when one exists, to decide whether the attribute exists. Every sequence of up to three calls to `add_class()`, `remove_class()`, `remove_attribute( 'class' )` and `set_attribute( 'class', ... )` was compared, on tags with no, an empty, a boolean, a single and a duplicated `class` attribute, against a new Tag Processor's reading of `get_updated_html()`. Before this change 254 of 5,550 sequences disagreed; after it, none do. `get_attribute( 'class' )` agreed in every sequence before and after. Follow-up to [62960]. Props jonsurrell. See #65967.
…sts. Each data provider row now makes its calls in a closure, in place of a list of method names and arguments, and states the HTML that `get_updated_html()` produces. The test asserts that HTML directly, in place of comparing the attribute names against a new Tag Processor's reading of the output, so each row shows that only the reported attribute names were wrong. The output was already correct before the fix. The duplicated `class` attribute row adds `c` in place of `b`, so its expected HTML, `<div class="c" >`, shows that the duplicate `class="b"` was removed. See #65967.
552cc3e to
6f44926
Compare
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
get_attribute_names_with_prefix()can disagree withget_updated_html()about theclassattribute whenadd_class()orremove_class()follows an enqueuedset_attribute( 'class', ... )orremove_attribute( 'class' )on the same tag. This is in released WordPress since r62960 (7.1.0), which made the method read enqueued updates.remove_class( 'a' )remove_attribute( 'class' )get_attribute_names_with_prefix( '' )array( 'class' )array()get_updated_html()<div class="b"><div class="b">The reverse also happens: on
<div>,set_attribute( 'class', 'a' )thenremove_class( 'a' )reportsclass, and the output has noclassattribute.The method flushes class name updates only when they could add or remove the
classattribute: a removal when the tag has the attribute, an addition when it does not. It decided whether the tag has the attribute from the input document alone. It now uses the enqueuedclassattribute update when one exists, which is the valueclass_name_updates_to_attributes_updates()starts from.Every sequence of up to three calls to
add_class(),remove_class(),remove_attribute( 'class' )andset_attribute( 'class', ... ), on tags with no, an empty, a boolean, a single and a duplicatedclassattribute, was compared with a new Tag Processor's reading ofget_updated_html(). On trunk 254 of 5,550 sequences disagree; with this change none do, and none of 55,550 sequences of up to four calls.get_attribute( 'class' )agrees in every sequence on both. The new data provider test has a case for each kind of mismatch.Trac ticket: https://core.trac.wordpress.org/ticket/65967
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Diagnosis, the sequence comparison, tests, implementation and description drafting.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.