Update convert_chars():

- Stop trying to remove `<title>` and `<category>` meta tags. They have not been used for many many years.
- Replacement of `<br>` with `<br />` and `<hr>` with `<hr />` is not needed for HTML 5.0. Also, these tags are formatted like that by the visual editor.
- Replace invalid HTML entities that might be pasted in the Text editor on save instead of on display.
Fixes #32335.
Built from https://develop.svn.wordpress.org/trunk@32896


git-svn-id: http://core.svn.wordpress.org/trunk@32867 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2015-06-21 00:59:26 +00:00
parent 095dfe5386
commit b9a4fefb08
3 changed files with 56 additions and 53 deletions

View File

@ -87,6 +87,7 @@ add_filter( 'post_mime_type', 'sanitize_mime_type' );
// Places to balance tags on input // Places to balance tags on input
foreach ( array( 'content_save_pre', 'excerpt_save_pre', 'comment_save_pre', 'pre_comment_content' ) as $filter ) { 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 ); add_filter( $filter, 'balanceTags', 50 );
} }

View File

@ -1503,11 +1503,7 @@ function sanitize_html_class( $class, $fallback = '' ) {
} }
/** /**
* Converts a number of characters from a string. * Converts lone & characters into `&#038;` (a.k.a. `&amp;`)
*
* Metadata tags `<title>` and `<category>` are removed, `<br>` and `<hr>` are
* converted into correct XHTML and Unicode characters are converted to the
* valid range.
* *
* @since 0.71 * @since 0.71
* *
@ -1516,58 +1512,64 @@ function sanitize_html_class( $class, $fallback = '' ) {
* @return string Converted string. * @return string Converted string.
*/ */
function convert_chars( $content, $deprecated = '' ) { function convert_chars( $content, $deprecated = '' ) {
if ( !empty( $deprecated ) ) if ( ! empty( $deprecated ) ) {
_deprecated_argument( __FUNCTION__, '0.71' ); _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', '&#038;$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( $wp_htmltranswinuni = array(
'&#128;' => '&#8364;', // the Euro sign '&#128;' => '&#8364;', // the Euro sign
'&#129;' => '', '&#129;' => '',
'&#130;' => '&#8218;', // these are Windows CP1252 specific characters '&#130;' => '&#8218;', // these are Windows CP1252 specific characters
'&#131;' => '&#402;', // they would look weird on non-Windows browsers '&#131;' => '&#402;', // they would look weird on non-Windows browsers
'&#132;' => '&#8222;', '&#132;' => '&#8222;',
'&#133;' => '&#8230;', '&#133;' => '&#8230;',
'&#134;' => '&#8224;', '&#134;' => '&#8224;',
'&#135;' => '&#8225;', '&#135;' => '&#8225;',
'&#136;' => '&#710;', '&#136;' => '&#710;',
'&#137;' => '&#8240;', '&#137;' => '&#8240;',
'&#138;' => '&#352;', '&#138;' => '&#352;',
'&#139;' => '&#8249;', '&#139;' => '&#8249;',
'&#140;' => '&#338;', '&#140;' => '&#338;',
'&#141;' => '', '&#141;' => '',
'&#142;' => '&#381;', '&#142;' => '&#381;',
'&#143;' => '', '&#143;' => '',
'&#144;' => '', '&#144;' => '',
'&#145;' => '&#8216;', '&#145;' => '&#8216;',
'&#146;' => '&#8217;', '&#146;' => '&#8217;',
'&#147;' => '&#8220;', '&#147;' => '&#8220;',
'&#148;' => '&#8221;', '&#148;' => '&#8221;',
'&#149;' => '&#8226;', '&#149;' => '&#8226;',
'&#150;' => '&#8211;', '&#150;' => '&#8211;',
'&#151;' => '&#8212;', '&#151;' => '&#8212;',
'&#152;' => '&#732;', '&#152;' => '&#732;',
'&#153;' => '&#8482;', '&#153;' => '&#8482;',
'&#154;' => '&#353;', '&#154;' => '&#353;',
'&#155;' => '&#8250;', '&#155;' => '&#8250;',
'&#156;' => '&#339;', '&#156;' => '&#339;',
'&#157;' => '', '&#157;' => '',
'&#158;' => '&#382;', '&#158;' => '&#382;',
'&#159;' => '&#376;' '&#159;' => '&#376;'
); );
// Remove metadata tags if ( strpos( $content, '&#1' ) !== false ) {
$content = preg_replace('/<title>(.+?)<\/title>/','',$content); $content = strtr( $content, $wp_htmltranswinuni );
$content = preg_replace('/<category>(.+?)<\/category>/','',$content); }
// Converts lone & characters into &#38; (a.k.a. &amp;)
$content = preg_replace('/&([^#])(?![a-z1-4]{1,8};)/i', '&#038;$1', $content);
// Fix Word pasting
$content = strtr($content, $wp_htmltranswinuni);
// Just a little XHTML help
$content = str_replace('<br>', '<br />', $content);
$content = str_replace('<hr>', '<hr />', $content);
return $content; return $content;
} }

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.3-alpha-32895'; $wp_version = '4.3-alpha-32896';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.