Skip to content

Commit

Permalink
Refactor ImageCDN parsing to rely on HTML API instead of RegExps (#32700
Browse files Browse the repository at this point in the history
)

* Refactor ImageCDN parsing to rely on HTML API instead of RegExps (#32700)

The introduction of the HTML API into WordPress 6.2 offers a new method of
matching and modifying HTML. In this patch we're replacing code that attempts
to parse the input HTML and visit all images, then read and modify them based
on the values of their attributes and computed Photon properties.

In the previous code the `Image_CDN` class scanned the entire HTML document to
generate a list of PREG image match objects, then iterated over those matches
and performed string-replace operations on them.

Now the class does a pass from start to finish, visting each image tag along
the way, and making the appropriate modifications.

Co-authored-by: Adnan Haque <[email protected]>
Co-authored-by: Brandon Kraft <[email protected]>
Co-authored-by: Jeremy Herve <[email protected]>
Co-authored-by: Mark George <[email protected]>
Co-authored-by: Osk <[email protected]>

* Rearrange semantically equivalent test output to avoid false negatives.

No `assertEquivalentMarkup` exists yet, so this gets around that without
creating one.

* Fix broken test

* Remove unnecessary comment

* Fix static analysis issues

* Fix static analysis issue

* Bump project version to 0.4.7-alpha

* Fix project version

---------

Co-authored-by: Adnan Haque <[email protected]>
Co-authored-by: Brandon Kraft <[email protected]>
Co-authored-by: Jeremy Herve <[email protected]>
Co-authored-by: Mark George <[email protected]>
Co-authored-by: Osk <[email protected]>
Co-authored-by: Peter Petrov <[email protected]>
  • Loading branch information
7 people authored Aug 28, 2024
1 parent e097da3 commit 6dd0cf2
Show file tree
Hide file tree
Showing 3 changed files with 308 additions and 241 deletions.
4 changes: 4 additions & 0 deletions projects/packages/image-cdn/changelog/html-api-for-image-cdn
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Rely on WordPress HTML API to parse HTML instead of Regex
Loading

0 comments on commit 6dd0cf2

Please sign in to comment.