Changeset 48072 for trunk/src/wp-includes/kses.php
- Timestamp:
- 06/17/2020 03:22:49 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/kses.php
r47892 r48072 48 48 // Ensure that these variables are added to the global namespace 49 49 // (e.g. if using namespaces / autoload in the current PHP environment). 50 global $allowedposttags, $allowedtags, $allowedentitynames ;50 global $allowedposttags, $allowedtags, $allowedentitynames, $allowedxmlentitynames; 51 51 52 52 if ( ! CUSTOM_TAGS ) { … … 705 705 ); 706 706 707 /** 708 * @var string[] $allowedxmlentitynames Array of KSES allowed XML entitity names. 709 * @since 5.5.0 710 */ 711 $allowedxmlnamedentities = array( 712 'amp', 713 'lt', 714 'gt', 715 'apos', 716 'quot', 717 ); 718 707 719 $allowedposttags = array_map( '_wp_add_global_attributes', $allowedposttags ); 708 720 } else { … … 1746 1758 * `AT&T`, `:` to `:`, `&#XYZZY;` to `&#XYZZY;` and so on. 1747 1759 * 1760 * When `$context` is set to 'xml', HTML entities are converted to their code points. For 1761 * example, `AT&T…&#XYZZY;` is converted to `AT&T…&#XYZZY;`. 1762 * 1748 1763 * @since 1.0.0 1749 * 1750 * @param string $string Content to normalize entities. 1764 * @since 5.5.0 Added `$context` parameter. 1765 * 1766 * @param string $string Content to normalize entities. 1767 * @param string $context Context for normalization. Can be either 'html' or 'xml'. 1768 * Default 'html'. 1751 1769 * @return string Content with normalized entities. 1752 1770 */ 1753 function wp_kses_normalize_entities( $string ) {1771 function wp_kses_normalize_entities( $string, $context = 'html' ) { 1754 1772 // Disarm all entities by converting & to & 1755 1773 $string = str_replace( '&', '&', $string ); 1756 1774 1757 1775 // Change back the allowed entities in our entity whitelist. 1758 $string = preg_replace_callback( '/&([A-Za-z]{2,8}[0-9]{0,2});/', 'wp_kses_named_entities', $string ); 1776 if ( 'xml' === $context ) { 1777 $string = preg_replace_callback( '/&([A-Za-z]{2,8}[0-9]{0,2});/', 'wp_kses_xml_named_entities', $string ); 1778 } else { 1779 $string = preg_replace_callback( '/&([A-Za-z]{2,8}[0-9]{0,2});/', 'wp_kses_named_entities', $string ); 1780 } 1759 1781 $string = preg_replace_callback( '/&#(0*[0-9]{1,7});/', 'wp_kses_normalize_entities2', $string ); 1760 1782 $string = preg_replace_callback( '/&#[Xx](0*[0-9A-Fa-f]{1,6});/', 'wp_kses_normalize_entities3', $string ); … … 1785 1807 $i = $matches[1]; 1786 1808 return ( ! in_array( $i, $allowedentitynames, true ) ) ? "&$i;" : "&$i;"; 1809 } 1810 1811 /** 1812 * Callback for `wp_kses_normalize_entities()` regular expression. 1813 * 1814 * This function only accepts valid named entity references, which are finite, 1815 * case-sensitive, and highly scrutinized by XML validators. HTML named entity 1816 * references are converted to their code points. 1817 * 1818 * @since 5.5.0 1819 * 1820 * @global array $allowedentitynames 1821 * @global array $allowedxmlnamedentities 1822 * 1823 * @param array $matches preg_replace_callback() matches array. 1824 * @return string Correctly encoded entity. 1825 */ 1826 function wp_kses_xml_named_entities( $matches ) { 1827 global $allowedentitynames, $allowedxmlnamedentities; 1828 1829 if ( empty( $matches[1] ) ) { 1830 return ''; 1831 } 1832 1833 $i = $matches[1]; 1834 1835 if ( in_array( $i, $allowedxmlnamedentities, true ) ) { 1836 return "&$i;"; 1837 } elseif ( in_array( $i, $allowedentitynames, true ) ) { 1838 return html_entity_decode( "&$i;", ENT_HTML5 ); 1839 } 1840 1841 return "&$i;"; 1787 1842 } 1788 1843
Note: See TracChangeset
for help on using the changeset viewer.