[wp-trac] [WordPress Trac] #58179: HTML API: Accumulate shift for internal parsing pointer.

WordPress Trac noreply at wordpress.org
Sun Apr 23 20:20:43 UTC 2023


#58179: HTML API: Accumulate shift for internal parsing pointer.
--------------------------+--------------------------------------
 Reporter:  dmsnell       |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  HTML API      |    Version:  6.2
 Severity:  normal        |   Keywords:  has-patch has-unit-tests
  Focuses:                |
--------------------------+--------------------------------------
 Github PR [https://github.com/WordPress/wordpress-develop/pull/4371 #4371]

 While working on [https://github.com/WordPress/block-interactivity-
 experiments/pull/141 WordPress/block-interactivity-experiments#141]
 @ockham discovered that the Tag Processor was making a small mistake.
 After making some updates the parser wasn't returning to the start of the
 affected tag. A test case was created in [https://github.com/WordPress
 /wordpress-develop/pull/4355 WordPress/wordpress-develop#4355].

 In few words, the Tag Processor has not been treating its own internal
 pointer `bytes_already_parsed` the same way it treats its bookmarks. That
 is, when updates are applied to the input document and then
 `get_updated_html()` is called, the internal pointer transfers to the
 newly-updated content as if no updates had been applied since the previous
 call to `get_updated_html()`.

 In this patch we're creating a new "shift accumulator" to account for all
 of the updates that accrue before calling `get_updated_html()`. This
 accumulated shift will be applied when swapping the input document with
 the output buffer, which should result in the pointer pointing to the same
 logical spot in the document it did before the udpate.

 In effect this patch adds a single workaround for treating the internal
 pointer like a bookmark, plus a temporary pointer which points to the
 beginning of the current tag when calling `get_updated_html()`. This will
 preserve the assumption that updating a document doesn't move that
 pointer, or shift which tag is currently matched.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58179>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list