External Libraries: Update the SimplePie library to version 1.5.7.

This version shows significant improvements in the compatibility of SimplePie with PHP 8.0, 8.1, and even contains an initial PHP 8.2 fix. The release also contains a number of other bug fixes.

Release notes: https://github.com/simplepie/simplepie/releases/tag/1.5.7

For a full list of changes in this update, see the SimplePie GitHub:
https://github.com/simplepie/simplepie/compare/1.5.6...1.5.7

Follow-up to [47733], [49176].

Props jrf, SergeyBiryukov.
Fixes #54659.

git-svn-id: https://develop.svn.wordpress.org/trunk@52393 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2021-12-20 19:31:37 +00:00
parent e169c4923b
commit 61dbb11d70
11 changed files with 217 additions and 26 deletions

View File

@@ -71,6 +71,15 @@ class SimplePie_Sanitize
var $useragent = '';
var $force_fsockopen = false;
var $replace_url_attributes = null;
var $registry;
/**
* List of domains for which to force HTTPS.
* @see SimplePie_Sanitize::set_https_domains()
* Array is a tree split at DNS levels. Example:
* array('biz' => true, 'com' => array('example' => true), 'net' => array('example' => array('www' => true)))
*/
var $https_domains = array();
public function __construct()
{
@@ -241,6 +250,68 @@ class SimplePie_Sanitize
$this->replace_url_attributes = (array) $element_attribute;
}
/**
* Set the list of domains for which to force HTTPS.
* @see SimplePie_Misc::https_url()
* Example array('biz', 'example.com', 'example.org', 'www.example.net');
*/
public function set_https_domains($domains)
{
$this->https_domains = array();
foreach ($domains as $domain)
{
$domain = trim($domain, ". \t\n\r\0\x0B");
$segments = array_reverse(explode('.', $domain));
$node =& $this->https_domains;
foreach ($segments as $segment)
{//Build a tree
if ($node === true)
{
break;
}
if (!isset($node[$segment]))
{
$node[$segment] = array();
}
$node =& $node[$segment];
}
$node = true;
}
}
/**
* Check if the domain is in the list of forced HTTPS.
*/
protected function is_https_domain($domain)
{
$domain = trim($domain, '. ');
$segments = array_reverse(explode('.', $domain));
$node =& $this->https_domains;
foreach ($segments as $segment)
{//Explore the tree
if (isset($node[$segment]))
{
$node =& $node[$segment];
}
else
{
break;
}
}
return $node === true;
}
/**
* Force HTTPS for selected Web sites.
*/
public function https_url($url)
{
return (strtolower(substr($url, 0, 7)) === 'http://') &&
$this->is_https_domain(parse_url($url, PHP_URL_HOST)) ?
substr_replace($url, 's', 4, 0) : //Add the 's' to HTTPS
$url;
}
public function sanitize($data, $type, $base = '')
{
$data = trim($data);
@@ -443,6 +514,7 @@ class SimplePie_Sanitize
$value = $this->registry->call('Misc', 'absolutize_url', array($element->getAttribute($attribute), $this->base));
if ($value !== false)
{
$value = $this->https_url($value);
$element->setAttribute($attribute, $value);
}
}