Make WordPress Core

Changeset 59070


Ignore:
Timestamp:
09/19/2024 08:20:30 PM (3 months ago)
Author:
hellofromTonya
Message:

External Libraries: Skip instanceof check when null in Text_Diff::_check().

On the first foreach loop in Text_Diff::_check(), $prevtype is null. As instanceof` requires the class name term to be an object or string, a fatal error is thrown:

Fatal error: Uncaught Error: Class name must be a valid object or a string on line 279

This change:

  • Adds a simple test for the Text_Diff::_check() method, which is how the bug was discovered as the test could never pass with the code as-is.
  • Adds a defensive guard to protect against the fatal. It checks if $prevtype is not null as a pre-condition to for checking the instance. This bugfix also resolves the failing test.

Follow-up to [49194], [7747].

Props jrf, hellofromTonya.
See #62083.

Location:
trunk
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/Text/Diff.php

    r57309 r59070  
    277277        $prevtype = null;
    278278        foreach ($this->_edits as $edit) {
    279             if ($edit instanceof $prevtype) {
     279            if ($prevtype !== null && $edit instanceof $prevtype) {
    280280                trigger_error("Edit sequence is non-optimal", E_USER_ERROR);
    281281            }
Note: See TracChangeset for help on using the changeset viewer.