Changeset 48072 for trunk/src/wp-includes/formatting.php
- Timestamp:
- 06/17/2020 03:22:49 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/formatting.php
r48048 r48072 936 936 * 937 937 * @since 1.2.2 938 * @since 5.5.0 `$quote_style` also accepts '`ENT_XML1`. 938 939 * @access private 939 940 * … … 943 944 * @param int|string $quote_style Optional. Converts double quotes if set to ENT_COMPAT, 944 945 * both single and double if set to ENT_QUOTES or none if set to ENT_NOQUOTES. 945 * Also compatible with old values; converting single quotes if set to 'single', 946 * Converts single and double quotes, as well as converting HTML 947 * named entities (that are not also XML named entities) to their 948 * code points if set to ENT_XML1. Also compatible with old values; 949 * converting single quotes if set to 'single', 946 950 * double if set to 'double' or both if otherwise set. 947 951 * Default is ENT_NOQUOTES. … … 965 969 if ( empty( $quote_style ) ) { 966 970 $quote_style = ENT_NOQUOTES; 967 } elseif ( ! in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) { 971 } elseif ( ENT_XML1 === $quote_style ) { 972 $quote_style = ENT_QUOTES | ENT_XML1; 973 } elseif ( ! in_array( $quote_style, array( ENT_NOQUOTES, ENT_COMPAT, ENT_QUOTES, 'single', 'double' ), true ) ) { 968 974 $quote_style = ENT_QUOTES; 969 975 } … … 995 1001 // Guarantee every &entity; is valid, convert &garbage; into &garbage; 996 1002 // This is required for PHP < 5.4.0 because ENT_HTML401 flag is unavailable. 997 $string = wp_kses_normalize_entities( $string );1003 $string = wp_kses_normalize_entities( $string, ( $quote_style & ENT_XML1 ) ? 'xml' : 'html' ); 998 1004 } 999 1005 … … 4538 4544 4539 4545 /** 4546 * Escaping for XML blocks. 4547 * 4548 * @since 5.5.0 4549 * 4550 * @param string $text Text to escape. 4551 * @return string Escaped text. 4552 */ 4553 function esc_xml( $text ) { 4554 $safe_text = wp_check_invalid_utf8( $text ); 4555 4556 $cdata_regex = '\<\!\[CDATA\[.*?\]\]\>'; 4557 $regex = <<<EOF 4558 / 4559 (?=.*?{$cdata_regex}) # lookahead that will match anything followed by a CDATA Section 4560 (?<non_cdata_followed_by_cdata>(.*?)) # the "anything" matched by the lookahead 4561 (?<cdata>({$cdata_regex})) # the CDATA Section matched by the lookahead 4562 4563 | # alternative 4564 4565 (?<non_cdata>(.*)) # non-CDATA Section 4566 /sx 4567 EOF; 4568 4569 $safe_text = (string) preg_replace_callback( 4570 $regex, 4571 static function( $matches ) { 4572 if ( ! $matches[0] ) { 4573 return ''; 4574 } 4575 4576 if ( ! empty( $matches['non_cdata'] ) ) { 4577 // escape HTML entities in the non-CDATA Section. 4578 return _wp_specialchars( $matches['non_cdata'], ENT_XML1 ); 4579 } 4580 4581 // Return the CDATA Section unchanged, escape HTML entities in the rest. 4582 return _wp_specialchars( $matches['non_cdata_followed_by_cdata'], ENT_XML1 ) . $matches['cdata']; 4583 }, 4584 $safe_text 4585 ); 4586 4587 /** 4588 * Filters a string cleaned and escaped for output in XML. 4589 * 4590 * Text passed to esc_xml() is stripped of invalid or special characters 4591 * before output. HTML named character references are converted to their 4592 * equivalent code points. 4593 * 4594 * @since 5.5.0 4595 * 4596 * @param string $safe_text The text after it has been escaped. 4597 * @param string $text The text prior to being escaped. 4598 */ 4599 return apply_filters( 'esc_xml', $safe_text, $text ); 4600 } 4601 4602 /** 4540 4603 * Escape an HTML tag name. 4541 4604 *
Note: See TracChangeset
for help on using the changeset viewer.