Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tag Processor: Fix a problem backing up too far after updating HTML #46597

Closed
wants to merge 99 commits into from

Conversation

dmsnell
Copy link
Member

@dmsnell dmsnell commented Dec 15, 2022

What

Fixes a bug in the HTML Tag Processor when updating a document when the internal pointer is at the first tag in the document.

Why?

The Tag Processor shouldn't break code relying on it.

How?

A defect introduced in #46018 led to the tag processor backing up one index too far after flushing its queued changes on a document.

For most operations this didn't cause any harm because when immediately moving forward after an update, the next_tag() returned to the same spot: it was backing up to one position before the current tag instead of at the start of the current tag.

Unfortunately, when the current tag was the first in the document this would lead the processor to rewind to position -1, right before the start of the document, and lead to errors with strpos() when it received out-of-bounds indices.

In this fix we're correcting the adjustment for the HTML tag's < and documenting the math in the file so that it's clearer why it's there and providing guidance should another fix be necessary.

Props to @anton-vlasenko for finding this bug.

Testing Instructions

Run the PHP unit test suite with PHP <= 7.0.
Tests should start failing in trunk but should pass in this branch.

Temporarily rebasing against fix/parity-with-cores-php-ci-jobs in this PR to run such tests in CI.

anton-vlasenko and others added 30 commits December 13, 2022 16:43
Run tests in phpunit-test.yml instead.
…the PHP version varies, the same PHP version needs to be configured for the action runner.
youknowriad and others added 11 commits December 15, 2022 16:36
* Lodash: Refactor components away from _.find()

* Add CHANGELOG entry
Co-authored-by: Ben Dwyer <ben@escruffian.com>
Co-authored-by: Glen Davies <glen.davies@automattic.com>
* Migrate qupte e2e tests to playwright

* Use inline snapshots

* Add `deleteAllPosts`

* Use accesible selector

* Add an inline comment for `pressKeyTimes`
A defect introduced in #46018 led to the tag processor backing up
one index too far after flushing its queued changes on a document.

For most operations this didn't cause any harm because when immediately
moving forward after an update, the `next_tag()` returned to the same
spot: it was backing up to one position before the current tag instead
of at the start of the current tag.

Unfortunately, when the current tag was the first in the document this
would lead the processor to rewind to position `-1`, right before the
start of the document, and lead to errors with `strpos()` when it
received out-of-bounds indices.

In this fix we're correcting the adjustment for the HTML tag's `<` and
documenting the math in the file so that it's clearer why it's there
and providing guidance should another fix be necessary.

Props to @anton-vlasenko for finding this bug.
@dmsnell dmsnell force-pushed the fix/tag-processor-back-too-far branch from 133b0d2 to bdea1f3 Compare December 15, 2022 23:36
@dmsnell dmsnell changed the base branch from trunk to fix/parity-with-cores-php-ci-jobs December 15, 2022 23:37
@dmsnell dmsnell changed the base branch from fix/parity-with-cores-php-ci-jobs to trunk December 15, 2022 23:37
@dmsnell
Copy link
Member Author

dmsnell commented Dec 15, 2022

Blarg

@dmsnell dmsnell closed this Dec 15, 2022
@dmsnell dmsnell deleted the fix/tag-processor-back-too-far branch December 15, 2022 23:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.