[wp-trac] [WordPress Trac] #60480: preg_match() warning in wp_image_add_srcset_and_sizes() when image_meta['file'] is missing

WordPress Trac noreply at wordpress.org
Tue Jan 13 22:14:23 UTC 2026


#60480: preg_match() warning in wp_image_add_srcset_and_sizes() when
image_meta['file'] is missing
--------------------------+--------------------------
 Reporter:  shanemac10    |       Owner:  westonruter
     Type:  defect (bug)  |      Status:  reviewing
 Priority:  normal        |   Milestone:  7.0
Component:  Import        |     Version:  4.4
 Severity:  major         |  Resolution:
 Keywords:  has-patch     |     Focuses:  performance
--------------------------+--------------------------
Changes (by westonruter):

 * owner:  (none) => westonruter
 * status:  assigned => reviewing
 * version:  6.4.3 => 4.4


Comment:

 Replying to [comment:5 sabernhardt]:
 > If the `wp_image_add_srcset_and_sizes()` checks for the 'file' array
 key, I think it could check at the same time as the 'sizes' array key.
 (Note: I have not tested this.)

 I'm not sure that's going to be equivalent. There is still logic that the
 function is supposed to do if `$image_meta['file']` is not set. It's just
 supposed to use that `file` get to “Bail early if an image has been
 inserted and later edited.”

 The code in question was introduced in [35412] for #34430. Cc @joemcgill
 in case he has anything to add.

 Otherwise, the patch looks right to me. I don't see any test coverage for
 `wp_image_add_srcset_and_sizes()`. That would be nice to add, but this
 seems like a straightforward change. It just prevents passing `null` to
 `preg_match()` with the pattern `/-e[0-9]{13}/`. In versions of PHP prior
 to 8.1, the `null` would silently be treated the same as an empty string:
 https://3v4l.org/oY5nou#veol

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/60480#comment:14>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list