Make WordPress Core


Ignore:
Timestamp:
07/02/2025 12:33:10 PM (3 months ago)
Author:
jonsurrell
Message:

Docs: Expand valid_unicode function documentation.

The valid_unicode() function accepts a limited set of codepoints according to the XML specification. Document the allowed codepoints and link to relevant documentation.

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

Props jonsurrell, dmsnell.
See #6583, #63166.

File:
1 edited

Legend:

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

    r59677 r60405  
    20842084 * Determines if a Unicode codepoint is valid.
    20852085 *
     2086 * The definition of a valid Unicode codepoint is taken from the XML definition:
     2087 *
     2088 * > Characters
     2089 * >
     2090 * > …
     2091 * > Legal characters are tab, carriage return, line feed, and the legal characters of
     2092 * > Unicode and ISO/IEC 10646.
     2093 * > …
     2094 * > Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
     2095 *
    20862096 * @since 2.7.0
     2097 *
     2098 * @see https://www.w3.org/TR/xml/#charsets
    20872099 *
    20882100 * @param int $i Unicode codepoint.
     
    20922104    $i = (int) $i;
    20932105
    2094     return ( 0x9 === $i || 0xa === $i || 0xd === $i ||
    2095         ( 0x20 <= $i && $i <= 0xd7ff ) ||
    2096         ( 0xe000 <= $i && $i <= 0xfffd ) ||
    2097         ( 0x10000 <= $i && $i <= 0x10ffff )
     2106    return (
     2107        0x9 === $i || // U+0009 HORIZONTAL TABULATION (HT)
     2108        0xA === $i || // U+000A LINE FEED (LF)
     2109        0xD === $i || // U+000D CARRIAGE RETURN (CR)
     2110        /*
     2111         * The valid Unicode characters according to the XML specification:
     2112         *
     2113         * > any Unicode character, excluding the surrogate blocks, FFFE, and FFFF.
     2114         */
     2115        ( 0x20 <= $i && $i <= 0xD7FF ) ||
     2116        ( 0xE000 <= $i && $i <= 0xFFFD ) ||
     2117        ( 0x10000 <= $i && $i <= 0x10FFFF )
    20982118    );
    20992119}
Note: See TracChangeset for help on using the changeset viewer.