diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php
index 93fac65c7d..8d926e698e 100644
--- a/src/wp-includes/default-filters.php
+++ b/src/wp-includes/default-filters.php
@@ -87,6 +87,7 @@ add_filter( 'post_mime_type', 'sanitize_mime_type' );
// Places to balance tags on input
foreach ( array( 'content_save_pre', 'excerpt_save_pre', 'comment_save_pre', 'pre_comment_content' ) as $filter ) {
+ add_filter( $filter, 'convert_invalid_entities' );
add_filter( $filter, 'balanceTags', 50 );
}
diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php
index f255942b29..e295167e0e 100644
--- a/src/wp-includes/formatting.php
+++ b/src/wp-includes/formatting.php
@@ -1503,11 +1503,7 @@ function sanitize_html_class( $class, $fallback = '' ) {
}
/**
- * Converts a number of characters from a string.
- *
- * Metadata tags `
` and `` are removed, `
` and `
` are
- * converted into correct XHTML and Unicode characters are converted to the
- * valid range.
+ * Converts lone & characters into `&` (a.k.a. `&`)
*
* @since 0.71
*
@@ -1516,58 +1512,64 @@ function sanitize_html_class( $class, $fallback = '' ) {
* @return string Converted string.
*/
function convert_chars( $content, $deprecated = '' ) {
- if ( !empty( $deprecated ) )
+ if ( ! empty( $deprecated ) ) {
_deprecated_argument( __FUNCTION__, '0.71' );
+ }
- // Translation of invalid Unicode references range to valid range
+ if ( strpos( $content, '&' ) !== false ) {
+ $content = preg_replace( '/&([^#])(?![a-z1-4]{1,8};)/i', '&$1', $content );
+ }
+
+ return $content;
+}
+
+/**
+ * Converts invalid Unicode references range to valid range.
+ *
+ * @since 4.3
+ *
+ * @param string $content String with entities that need converting.
+ * @return string Converted string.
+ */
+function convert_invalid_entities( $content ) {
$wp_htmltranswinuni = array(
- '' => '€', // the Euro sign
- '' => '',
- '' => '‚', // these are Windows CP1252 specific characters
- '' => 'ƒ', // they would look weird on non-Windows browsers
- '' => '„',
- '
' => '…',
- '' => '†',
- '' => '‡',
- '' => 'ˆ',
- '' => '‰',
- '' => 'Š',
- '' => '‹',
- '' => 'Œ',
- '' => '',
- '' => 'Ž',
- '' => '',
- '' => '',
- '' => '‘',
- '' => '’',
- '' => '“',
- '' => '”',
- '' => '•',
- '' => '–',
- '' => '—',
- '' => '˜',
- '' => '™',
- '' => 'š',
- '' => '›',
- '' => 'œ',
- '' => '',
- '' => 'ž',
- '' => 'Ÿ'
+ '' => '€', // the Euro sign
+ '' => '',
+ '' => '‚', // these are Windows CP1252 specific characters
+ '' => 'ƒ', // they would look weird on non-Windows browsers
+ '' => '„',
+ '
' => '…',
+ '' => '†',
+ '' => '‡',
+ '' => 'ˆ',
+ '' => '‰',
+ '' => 'Š',
+ '' => '‹',
+ '' => 'Œ',
+ '' => '',
+ '' => 'Ž',
+ '' => '',
+ '' => '',
+ '' => '‘',
+ '' => '’',
+ '' => '“',
+ '' => '”',
+ '' => '•',
+ '' => '–',
+ '' => '—',
+ '' => '˜',
+ '' => '™',
+ '' => 'š',
+ '' => '›',
+ '' => 'œ',
+ '' => '',
+ '' => 'ž',
+ '' => 'Ÿ'
);
- // Remove metadata tags
- $content = preg_replace('/(.+?)<\/title>/','',$content);
- $content = preg_replace('/(.+?)<\/category>/','',$content);
-
- // Converts lone & characters into & (a.k.a. &)
- $content = preg_replace('/&([^#])(?![a-z1-4]{1,8};)/i', '&$1', $content);
-
- // Fix Word pasting
- $content = strtr($content, $wp_htmltranswinuni);
-
- // Just a little XHTML help
- $content = str_replace('
', '
', $content);
- $content = str_replace('
', '
', $content);
+ if ( strpos( $content, '' ) !== false ) {
+ $content = strtr( $content, $wp_htmltranswinuni );
+ }
return $content;
}