Make WordPress Core

Opened 8 years ago

Closed 4 months ago

Last modified 7 weeks ago

#43224 closed enhancement (fixed)

Extract `$utf8_pcre` from `wp_check_invalid_utf8()` into a separate function

Reported by: jaswrks's profile jaswrks Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Formatting Keywords:
Focuses: Cc:

Description

The wp_check_invalid_utf8() function checks to confirm support for the /u flag in regular expressions. The result of that check is cached in a static variable within that function. However, other areas of the codebase might want to run the same check, or maybe plugins would like to check also.

I'm considering a change in Gutenberg's PEG parser and that might serve as an example use case for the new wp_can_utf8_pcre() function I'm proposing in this ticket. Instead of running the same check all over again, having this check run once by a utility function would be nice.

See: https://github.com/WordPress/gutenberg/blob/daad3f21319ec9ec73fa1b907119a7464442bfac/lib/parser.php#L1818

Attachments (1)

43224.patch (1.1 KB) - added by jaswrks 8 years ago.

Download all attachments as: .zip

Change History (9)

@jaswrks
8 years ago

#2 @jaswrks
8 years ago

Update: The Gutenberg PEG parser is actually generated by a JavaScript library, so maybe it's not the best example of a use case for this. However, I still think the patch is worth considering; i.e., a good idea for this to be extracted so it can be used by other functions.

Version 0, edited 8 years ago by jaswrks (next)

#3 @jnylen0
8 years ago

The information in this ticket is correct, but this function already exists in WP, almost exactly as written in the patch:

https://core.trac.wordpress.org/browser/tags/4.9.5/src/wp-includes/compat.php#L16

Introduced here: https://core.trac.wordpress.org/changeset/32364#file2

It would be good to refactor wp_check_invalid_utf8 to use the shared function rather than doing its own thing.

#4 @pento
7 years ago

  • Version trunk deleted

#5 follow-up: @dmsnell
4 months ago

  • Resolution set to fixed
  • Status changed from new to closed

Resolved in [32364] when _wp_can_use_pcre_u() was introduced.

#6 in reply to: ↑ 5 @desrosj
4 months ago

Replying to dmsnell:

Resolved in [32364] when _wp_can_use_pcre_u() was introduced.

Could you double check this? Is this the right changeset? [32364] was merged 10 years ago, but this ticket was opened just 8 years ago.

#7 @dmsnell
4 months ago

Thanks for asking for the double-check @desrosj — it never hurts.

Perhaps there is another resolution more appropriate here, but I took this statement from the ticket as the dominant ask:

other areas of the codebase might want to run the same check, or maybe plugins would like to check also

That is, this is less about removing the ad-hoc check from wp_check_invalid_utf8() and more about abstracting the check and making it available. It may have simply been the case that it was already available when this ticket was created and that wasn’t clear.

Either way, the function has been available and it’s no longer relevant in wp_check_invalid_utf8() since it was refactored in [60793].

#8 @swissspidy
7 weeks ago

  • Milestone Awaiting Review deleted

Removing milestone from closed ticket.

Note: See TracTickets for help on using tickets.