Skip to content

Audit usage of mb_* functions in PHP parser #1611

Closed

Description

The generated PHP parser contains several instances of mb_* (multibyte string) functions:

     38 mb_substr(
      6 mb_strlen(
      3 mb_regex_encoding(
      1 mb_eregi(
      1 mb_ereg(
      1 mb_convert_encoding(

However, PHP is not always installed with the mbstring extension enabled, so these functions do not always exist.

WP core has polyfills that attempt to emulate mb_substr and mb_strlen if they are not present; the rest of these functions are newly introduced and will cause errors under PHP configurations without these functions enabled.

There are a few options for how to proceed:

Polyfill the new functions

Converting encodings and matching regexes both seem quite complicated.

Decide that this is no longer an issue

This code in core has a lot of history, and I am not sure how common it is to have PHP installed without the mbstring extension. (It's not enabled in a default build of PHP, but this hasn't been a problem in distributions of PHP that I've used).

In particular there is a mention of yoast.com having this configuration, but from 6 years ago.

Replace the new functions with something else

Fortunately, mb_convert_encoding is only used to convert a character code to a UTF-8 character, and [I am pretty sure that] the mb_ereg and mb_eregi calls are only used to match very simple regular expressions of the form ^[charlist] against single characters. So the simplest path forward is probably to remove these calls from phpegjs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    [Feature] ParsingRelated to efforts to improving the parsing of a string of data and converting it into a different f[Priority] HighUsed to indicate top priority items that need quick attention[Type] BugAn existing feature does not function as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions