Make WordPress Core

Opened 2 days ago

Closed 2 days ago

#66483 closed enhancement (fixed)

KSES: Clarify that `valid_unicode()` checks XML Char ranges

Reported by: lancewillett Owned by: lancewillett
Priority: normal Milestone: 7.2
Component: Formatting Version:
Severity: normal Keywords:
Cc: Focuses:

Description

valid_unicode() does not check whether a code point is valid Unicode. It follows the XML Char production, so it rejects C0 controls other than tab, line feed and carriage return (for example U+0008 BACKSPACE), along with surrogates and U+FFFE and U+FFFF. Its name and docblock both say "valid Unicode", which invites new callers to use it for the wrong job.

The pull request:

  • Rewrites the docblock to say what the function checks, and points callers to the newer Unicode and UTF-8 helpers, such as wp_is_valid_utf8().
  • Adds rejected test cases for U+000B and U+001F. Each one is the only case that fails if the boundary below U+0020 moves.
  • Renames the test and its data provider to describe XML Char acceptance.

The function's behavior does not change. Deprecating it is left for a separate ticket.

Follow-up to [64770], which added the test coverage under #65819.

Change History (1)

#1 @lancewillett
2 days ago

  • Owner set to lancewillett
  • Resolution → fixed
  • Status new → closed

In 65268:

KSES: Clarify that valid_unicode() checks XML Char ranges.

valid_unicode() follows the XML Char production rather than checking whether a code point is valid Unicode. It rejects C0 controls other than tab, line feed, and carriage return, along with surrogates and U+FFFE and U+FFFF. Update its docblock to say so, and point callers to the newer Unicode and UTF-8 helpers, such as wp_is_valid_utf8().

Add rejected test cases for U+000B and U+001F, which guard the boundary below U+0020, and rename the test and its data provider to describe XML Char acceptance.

Follow-up to [64770].

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/15105

Props shailu25, dmsnell.
Fixes #66483. See #65819.

Note: See TracTickets for help on using tickets.