Make WordPress Core


Ignore:
Timestamp:
05/01/2020 02:24:42 PM (5 years ago)
Author:
desrosj
Message:

External Libraries: Update the SimplePie library to the latest version (1.5.5).

This brings SimplePie in sync with the most up to date version, 1.5.5.

This update brings many bug fixes, small enhancements, and PHP compatibility fixes for newer versions of PHP.

For a full list of changes, see https://github.com/simplepie/simplepie/blob/master/CHANGELOG.md#155-may-1-2020.

Props dshanske, slushman, etruel, wpshades, dmenard, desrosj, hareesh-pillai, stevenkword, jrf, Ipstenu, johnbillion.
Fixes #36669.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/SimplePie/Sanitize.php

    r25342 r47733  
    66 * Takes the hard work out of managing a complete RSS/Atom solution.
    77 *
    8  * Copyright (c) 2004-2012, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
     8 * Copyright (c) 2004-2016, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
    99 * All rights reserved.
    1010 *
     
    3434 *
    3535 * @package SimplePie
    36  * @version 1.3.1
    37  * @copyright 2004-2012 Ryan Parman, Geoffrey Sneddon, Ryan McCue
     36 * @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue
    3837 * @author Ryan Parman
    39  * @author Geoffrey Sneddon
     38 * @author Sam Sneddon
    4039 * @author Ryan McCue
    4140 * @link http://simplepie.org/ SimplePie
     
    6261    var $strip_htmltags = array('base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style');
    6362    var $encode_instead_of_strip = false;
    64     var $strip_attributes = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
     63    var $strip_attributes = array('bgsound', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc');
     64    var $add_attributes = array('audio' => array('preload' => 'none'), 'iframe' => array('sandbox' => 'allow-scripts allow-same-origin'), 'video' => array('preload' => 'none'));
    6565    var $strip_comments = false;
    6666    var $output_encoding = 'UTF-8';
     
    161161    }
    162162
    163     public function strip_attributes($attribs = array('bgsound', 'class', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc'))
     163    public function strip_attributes($attribs = array('bgsound', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc'))
    164164    {
    165165        if ($attribs)
     
    177177        {
    178178            $this->strip_attributes = false;
     179        }
     180    }
     181
     182    public function add_attributes($attribs = array('audio' => array('preload' => 'none'), 'iframe' => array('sandbox' => 'allow-scripts allow-same-origin'), 'video' => array('preload' => 'none')))
     183    {
     184        if ($attribs)
     185        {
     186            if (is_array($attribs))
     187            {
     188                $this->add_attributes = $attribs;
     189            }
     190            else
     191            {
     192                $this->add_attributes = explode(',', $attribs);
     193            }
     194        }
     195        else
     196        {
     197            $this->add_attributes = false;
    179198        }
    180199    }
     
    250269                if (!class_exists('DOMDocument'))
    251270                {
    252                     $this->registry->call('Misc', 'error', array('DOMDocument not found, unable to use sanitizer', E_USER_WARNING, __FILE__, __LINE__));
    253                     return '';
     271                    throw new SimplePie_Exception('DOMDocument not found, unable to use sanitizer');
    254272                }
    255273                $document = new DOMDocument();
    256274                $document->encoding = 'UTF-8';
     275
    257276                $data = $this->preprocess($data, $type);
    258277
     
    261280                restore_error_handler();
    262281
     282                $xpath = new DOMXPath($document);
     283
    263284                // Strip comments
    264285                if ($this->strip_comments)
    265286                {
    266                     $xpath = new DOMXPath($document);
    267287                    $comments = $xpath->query('//comment()');
    268288
     
    280300                    foreach ($this->strip_htmltags as $tag)
    281301                    {
    282                         $this->strip_tag($tag, $document, $type);
     302                        $this->strip_tag($tag, $document, $xpath, $type);
    283303                    }
    284304                }
     
    288308                    foreach ($this->strip_attributes as $attrib)
    289309                    {
    290                         $this->strip_attr($attrib, $document);
     310                        $this->strip_attr($attrib, $xpath);
     311                    }
     312                }
     313
     314                if ($this->add_attributes)
     315                {
     316                    foreach ($this->add_attributes as $tag => $valuePairs)
     317                    {
     318                        $this->add_attr($tag, $valuePairs, $document);
    291319                    }
    292320                }
     
    327355                                    else
    328356                                    {
    329                                         trigger_error("$this->cache_location is not writeable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING);
     357                                        trigger_error("$this->cache_location is not writable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING);
    330358                                    }
    331359                                }
     
    335363                }
    336364
    337                 // Remove the DOCTYPE
    338                 // Seems to cause segfaulting if we don't do this
    339                 if ($document->firstChild instanceof DOMDocumentType)
    340                 {
    341                     $document->removeChild($document->firstChild);
    342                 }
    343 
    344                 // Move everything from the body to the root
    345                 $real_body = $document->getElementsByTagName('body')->item(0)->childNodes->item(0);
    346                 $document->replaceChild($real_body, $document->firstChild);
    347 
     365                // Get content node
     366                $div = $document->getElementsByTagName('body')->item(0)->firstChild;
    348367                // Finally, convert to a HTML string
    349                 $data = trim($document->saveHTML());
     368                $data = trim($document->saveHTML($div));
    350369
    351370                if ($this->remove_div)
     
    385404    {
    386405        $ret = '';
     406        $html = preg_replace('%</?(?:html|body)[^>]*?'.'>%is', '', $html);
    387407        if ($type & ~SIMPLEPIE_CONSTRUCT_XHTML)
    388408        {
     
    457477    }
    458478
    459     protected function strip_tag($tag, $document, $type)
    460     {
    461         $xpath = new DOMXPath($document);
     479    protected function strip_tag($tag, $document, $xpath, $type)
     480    {
    462481        $elements = $xpath->query('body//' . $tag);
    463482        if ($this->encode_instead_of_strip)
     
    542561    }
    543562
    544     protected function strip_attr($attrib, $document)
    545     {
    546         $xpath = new DOMXPath($document);
     563    protected function strip_attr($attrib, $xpath)
     564    {
    547565        $elements = $xpath->query('//*[@' . $attrib . ']');
    548566
     
    552570        }
    553571    }
     572
     573    protected function add_attr($tag, $valuePairs, $document)
     574    {
     575        $elements = $document->getElementsByTagName($tag);
     576        foreach ($elements as $element)
     577        {
     578            foreach ($valuePairs as $attrib => $value)
     579            {
     580                $element->setAttribute($attrib, $value);
     581            }
     582        }
     583    }
    554584}
Note: See TracChangeset for help on using the changeset viewer.