Make WordPress Core

Opened 7 months ago

Closed 7 months ago

Last modified 7 months ago

#60746 closed defect (bug) (fixed)

Interactivity API - Directives in tags with closing tag that is not visit by the tag processor don't work

Reported by: santosguillamot's profile santosguillamot Owned by: dmsnell's profile dmsnell
Milestone: 6.6 Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

Right now, if I add directives to tags with closing tag that is not visited by the tag processor, it breaks the whole server-side rendering processing.

This is the list of those tags: https://github.com/WordPress/wordpress-develop/blob/186eeafb6888431fdf445b2abf2036f0606edcd5/src/wp-includes/interactivity-api/class-wp-interactivity-api-directives-processor.php#L25-L34

For example, if I try to add a directive to an iframe, it breaks the processing.

Co-authored by @cbravobernal

Change History (11)

#1 @cbravobernal
7 months ago

  • Milestone changed from Awaiting Review to 6.5

This ticket was mentioned in PR #6247 on WordPress/wordpress-develop by @santosguillamot.


7 months ago
#2

  • Keywords has-patch has-unit-tests added

Trac ticket: https://core.trac.wordpress.org/ticket/60746

Right now, if I add directives to tags with closing tag that is not visited by the tag processor, it breaks the whole server-side rendering processing.

This is the list of those tags: https://github.com/WordPress/wordpress-develop/blob/186eeafb6888431fdf445b2abf2036f0606edcd5/src/wp-includes/interactivity-api/class-wp-interactivity-api-directives-processor.php#L25-L34

For example, if I try to add a directive to an iframe, it breaks the processing.

Co-authored by @cbravobernal

@swissspidy commented on PR #6247:


7 months ago
#3

cc for review: @luisherranz, maybe @westonruter too

@dmsnell commented on PR #6247:


7 months ago
#4

please ignore my last comment: I finally reproduced this and I think I can say that it's fixed already in #6120, which is supposed to go in to 6.5 anyway, and this gives it even more reason to do so.

what's happening?

once the attribute was updated and next_tag() is called, the Tag Processor applies the changes and then re-parses content. it wasn't doing that properly once it started scanning all tokens, because it was short-circuiting some logic to avoid sub-class methods from being called (e.g. you don't want WP_HTML_Processor::next_token() to be called and then mess with the HTML stack of open elements).

unfortunately this short-circuit was programmed with the old assumption that everything is a tag, and we missed updating it earlier in the cycle for all tokens, including the handling of special tokens.

in #6120 the Tag Processor creates its own internal base_class_next_token() that it calls so that all of the logic is repeated after applying updates and seeking. this resolves the issue here because it then is able to trap the start and end of the iframe tag as one token.

@dmsnell commented on PR #6247:


7 months ago
#5

This branch, without the proposed fix, but with the deferred updates PR passes the tests.
https://github.com/WordPress/wordpress-develop/pull/6250

@santosguillamot commented on PR #6247:


7 months ago
#6

Thanks a lot for taking a deeper look at it, @dmsnell ☺️

I've rebased trunk and reverted the proposed fix and I can confirm that the test passes now. I'll leave this pull request only with the new test to ensure it keeps working as expected in the future.

#7 @dmsnell
7 months ago

  • Owner set to dmsnell
  • Resolution set to fixed
  • Status changed from new to closed

In 57822:

Interactivity API: Ensure proper directive processing on special elements.

Adds a test to ensure proper processing of directives on special HTML elements,
or HTML which contains special elements. These special elements are defined by
the HTML API and are the HTML elements which cannot contain other tags, such as
the IFRAME, SCRIPT, TEXTAREA, TITLE, elements, etc...

The server diretive processor performs a custom tracking of HTML structure and
this test ensures it isn't mislead by the handling of those special elements.

Developed in https://github.com/WordPress/wordpress-develop/pull/6247
Discussed in https://core.trac.wordpress.org/ticket/60746

Props santosguillamot, cbravobernal, mukesh27, westonruter, swissspidy, dmsnell.
Follow-up to [57348].
Fixes #60746.

#9 @kebbet
7 months ago

This ticket is fixed in trunk but not 6.5. Should the ticket be reopened for backport or milestoned in 6.6?

Could you clarify @dmsnell ? Thanks!

#10 @dmsnell
7 months ago

@kebbet given that this only introduces test code I didn't think it was necessary to port into 6.5, but maybe I should have removed the milestone then?

If you think it needs the backport I can do that. Happy to take your advice.

#11 @dmsnell
7 months ago

  • Milestone changed from 6.5 to 6.6

Moving to 6.6 since it's not necessary to port into 6.5 on account of being test-only code

Note: See TracTickets for help on using tickets.