WordPress.org

Make WordPress Core

Changeset 32896


Ignore:
Timestamp:
06/21/2015 12:58:12 AM (4 years ago)
Author:
azaozz
Message:

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.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

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

    r32809 r32896  
    8888// Places to balance tags on input
    8989foreach ( array( 'content_save_pre', 'excerpt_save_pre', 'comment_save_pre', 'pre_comment_content' ) as $filter ) {
     90    add_filter( $filter, 'convert_invalid_entities' );
    9091    add_filter( $filter, 'balanceTags', 50 );
    9192}
  • trunk/src/wp-includes/formatting.php

    r32863 r32896  
    15041504
    15051505/**
    1506  * Converts a number of characters from a string.
    1507  *
    1508  * Metadata tags `<title>` and `<category>` are removed, `<br>` and `<hr>` are
    1509  * converted into correct XHTML and Unicode characters are converted to the
    1510  * valid range.
     1506 * Converts lone & characters into `&#038;` (a.k.a. `&amp;`)
    15111507 *
    15121508 * @since 0.71
     
    15171513 */
    15181514function convert_chars( $content, $deprecated = '' ) {
    1519     if ( !empty( $deprecated ) )
     1515    if ( ! empty( $deprecated ) ) {
    15201516        _deprecated_argument( __FUNCTION__, '0.71' );
    1521 
    1522     // Translation of invalid Unicode references range to valid range
     1517    }
     1518
     1519    if ( strpos( $content, '&' ) !== false ) {
     1520        $content = preg_replace( '/&([^#])(?![a-z1-4]{1,8};)/i', '&#038;$1', $content );
     1521    }
     1522
     1523    return $content;
     1524}
     1525
     1526/**
     1527 * Converts invalid Unicode references range to valid range.
     1528 *
     1529 * @since 4.3
     1530 *
     1531 * @param string $content String with entities that need converting.
     1532 * @return string Converted string.
     1533 */
     1534function convert_invalid_entities( $content ) {
    15231535    $wp_htmltranswinuni = array(
    1524     '&#128;' => '&#8364;', // the Euro sign
    1525     '&#129;' => '',
    1526     '&#130;' => '&#8218;', // these are Windows CP1252 specific characters
    1527     '&#131;' => '&#402;',  // they would look weird on non-Windows browsers
    1528     '&#132;' => '&#8222;',
    1529     '&#133;' => '&#8230;',
    1530     '&#134;' => '&#8224;',
    1531     '&#135;' => '&#8225;',
    1532     '&#136;' => '&#710;',
    1533     '&#137;' => '&#8240;',
    1534     '&#138;' => '&#352;',
    1535     '&#139;' => '&#8249;',
    1536     '&#140;' => '&#338;',
    1537     '&#141;' => '',
    1538     '&#142;' => '&#381;',
    1539     '&#143;' => '',
    1540     '&#144;' => '',
    1541     '&#145;' => '&#8216;',
    1542     '&#146;' => '&#8217;',
    1543     '&#147;' => '&#8220;',
    1544     '&#148;' => '&#8221;',
    1545     '&#149;' => '&#8226;',
    1546     '&#150;' => '&#8211;',
    1547     '&#151;' => '&#8212;',
    1548     '&#152;' => '&#732;',
    1549     '&#153;' => '&#8482;',
    1550     '&#154;' => '&#353;',
    1551     '&#155;' => '&#8250;',
    1552     '&#156;' => '&#339;',
    1553     '&#157;' => '',
    1554     '&#158;' => '&#382;',
    1555     '&#159;' => '&#376;'
     1536        '&#128;' => '&#8364;', // the Euro sign
     1537        '&#129;' => '',
     1538        '&#130;' => '&#8218;', // these are Windows CP1252 specific characters
     1539        '&#131;' => '&#402;',  // they would look weird on non-Windows browsers
     1540        '&#132;' => '&#8222;',
     1541        '&#133;' => '&#8230;',
     1542        '&#134;' => '&#8224;',
     1543        '&#135;' => '&#8225;',
     1544        '&#136;' => '&#710;',
     1545        '&#137;' => '&#8240;',
     1546        '&#138;' => '&#352;',
     1547        '&#139;' => '&#8249;',
     1548        '&#140;' => '&#338;',
     1549        '&#141;' => '',
     1550        '&#142;' => '&#381;',
     1551        '&#143;' => '',
     1552        '&#144;' => '',
     1553        '&#145;' => '&#8216;',
     1554        '&#146;' => '&#8217;',
     1555        '&#147;' => '&#8220;',
     1556        '&#148;' => '&#8221;',
     1557        '&#149;' => '&#8226;',
     1558        '&#150;' => '&#8211;',
     1559        '&#151;' => '&#8212;',
     1560        '&#152;' => '&#732;',
     1561        '&#153;' => '&#8482;',
     1562        '&#154;' => '&#353;',
     1563        '&#155;' => '&#8250;',
     1564        '&#156;' => '&#339;',
     1565        '&#157;' => '',
     1566        '&#158;' => '&#382;',
     1567        '&#159;' => '&#376;'
    15561568    );
    15571569
    1558     // Remove metadata tags
    1559     $content = preg_replace('/<title>(.+?)<\/title>/','',$content);
    1560     $content = preg_replace('/<category>(.+?)<\/category>/','',$content);
    1561 
    1562     // Converts lone & characters into &#38; (a.k.a. &amp;)
    1563     $content = preg_replace('/&([^#])(?![a-z1-4]{1,8};)/i', '&#038;$1', $content);
    1564 
    1565     // Fix Word pasting
    1566     $content = strtr($content, $wp_htmltranswinuni);
    1567 
    1568     // Just a little XHTML help
    1569     $content = str_replace('<br>', '<br />', $content);
    1570     $content = str_replace('<hr>', '<hr />', $content);
     1570    if ( strpos( $content, '&#1' ) !== false ) {
     1571        $content = strtr( $content, $wp_htmltranswinuni );
     1572    }
    15711573
    15721574    return $content;
Note: See TracChangeset for help on using the changeset viewer.