Make WordPress Core

Changeset 59001


Ignore:
Timestamp:
09/09/2024 10:10:09 PM (4 weeks ago)
Author:
dmsnell
Message:

HTML API: Add sentinels for unreachable code.

There are places in the HTML API code where some tools get confused and flag invalid types for the return of a function because they are unable to detect that the end of the function is unreachable.

Since PHP doesn't provide a way to encode total matching in the source code, this patch adds a few extra lines in those unreachable locations to satisfy any tooling which isn't able to fully analyze the code.

Additionally this serves as extra guarding in case someone changes these functions in a way which would break them and the existing test suite doesn't catch those breakages.

Developed in https://github.com/WordPress/wordpress-develop/pull/7315
Discussed in https://core.trac.wordpress.org/ticket/62018

Props dlh, dmsnell.
Fixes #62018.

Location:
trunk/src/wp-includes/html-api
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/html-api/class-wp-html-processor.php

    r58992 r59001  
    27712771            }
    27722772        }
     2773
     2774        $this->bail( 'Should not have been able to reach end of IN BODY processing. Check HTML API code.' );
     2775        // This unnecessary return prevents tools from inaccurately reporting type errors.
     2776        return false;
    27732777    }
    27742778
     
    46464650            }
    46474651        }
     4652
     4653        $this->bail( 'Should not have been able to reach end of IN FOREIGN CONTENT processing. Check HTML API code.' );
     4654        // This unnecessary return prevents tools from inaccurately reporting type errors.
     4655        return false;
    46484656    }
    46494657
     
    58795887            );
    58805888        }
     5889
     5890        $this->bail( 'Should not have reached end of HTML Integration Point detection: check HTML API code.' );
     5891        // This unnecessary return prevents tools from inaccurately reporting type errors.
     5892        return false;
    58815893    }
    58825894
  • trunk/src/wp-includes/html-api/class-wp-html-tag-processor.php

    r58985 r59001  
    29662966            }
    29672967        }
     2968
     2969        // This unnecessary return prevents tools from inaccurately reporting type errors.
     2970        return $tag_name;
    29682971    }
    29692972
Note: See TracChangeset for help on using the changeset viewer.