diff --git a/wp-includes/SimplePie/autoloader.php b/wp-includes/SimplePie/autoloader.php
index b1635ff15c..4356b456f9 100644
--- a/wp-includes/SimplePie/autoloader.php
+++ b/wp-includes/SimplePie/autoloader.php
@@ -1,46 +1,7 @@
- * @link http://galvani.cz/
- * @license http://www.opensource.org/licenses/bsd-license.php BSD License
- * @version 0.2.9
- */
+// SPDX-FileCopyrightText: 2004-2023 Ryan Parman, Sam Sneddon, Ryan McCue
+// SPDX-License-Identifier: BSD-3-Clause
+
+declare(strict_types=1);
use SimplePie\Cache\Redis;
@@ -16,6 +11,7 @@ class_exists('SimplePie\Cache\Redis');
// @trigger_error(sprintf('Using the "SimplePie_Cache_Redis" class is deprecated since SimplePie 1.7.0, use "SimplePie\Cache\Redis" instead.'), \E_USER_DEPRECATED);
+/** @phpstan-ignore-next-line */
if (\false) {
/** @deprecated since SimplePie 1.7.0, use "SimplePie\Cache\Redis" instead */
class SimplePie_Cache_Redis extends Redis
diff --git a/wp-includes/SimplePie/library/SimplePie/Caption.php b/wp-includes/SimplePie/library/SimplePie/Caption.php
index 1f3a475c87..0162101e76 100644
--- a/wp-includes/SimplePie/library/SimplePie/Caption.php
+++ b/wp-includes/SimplePie/library/SimplePie/Caption.php
@@ -1,46 +1,9 @@
data = $data;
}
@@ -96,7 +58,8 @@ class SimplePie_Decode_HTML_Entities
*/
public function parse()
{
- while (($this->position = strpos($this->data, '&', $this->position)) !== false) {
+ while (($position = strpos($this->data, '&', $this->position)) !== false) {
+ $this->position = $position;
$this->consume();
$this->entity();
$this->consumed = '';
@@ -108,7 +71,7 @@ class SimplePie_Decode_HTML_Entities
* Consume the next byte
*
* @access private
- * @return mixed The next byte, or false, if there is no more data
+ * @return string|false The next byte, or false, if there is no more data
*/
public function consume()
{
@@ -125,9 +88,9 @@ class SimplePie_Decode_HTML_Entities
*
* @access private
* @param string $chars Characters to consume
- * @return mixed A series of characters that match the range, or false
+ * @return string|false A series of characters that match the range, or false
*/
- public function consume_range($chars)
+ public function consume_range(string $chars)
{
if ($len = strspn($this->data, $chars, $this->position)) {
$data = substr($this->data, $this->position, $len);
@@ -143,6 +106,7 @@ class SimplePie_Decode_HTML_Entities
* Unconsume one byte
*
* @access private
+ * @return void
*/
public function unconsume()
{
@@ -154,6 +118,7 @@ class SimplePie_Decode_HTML_Entities
* Decode an entity
*
* @access private
+ * @return void
*/
public function entity()
{
@@ -187,9 +152,13 @@ class SimplePie_Decode_HTML_Entities
static $windows_1252_specials = [0x0D => "\x0A", 0x80 => "\xE2\x82\xAC", 0x81 => "\xEF\xBF\xBD", 0x82 => "\xE2\x80\x9A", 0x83 => "\xC6\x92", 0x84 => "\xE2\x80\x9E", 0x85 => "\xE2\x80\xA6", 0x86 => "\xE2\x80\xA0", 0x87 => "\xE2\x80\xA1", 0x88 => "\xCB\x86", 0x89 => "\xE2\x80\xB0", 0x8A => "\xC5\xA0", 0x8B => "\xE2\x80\xB9", 0x8C => "\xC5\x92", 0x8D => "\xEF\xBF\xBD", 0x8E => "\xC5\xBD", 0x8F => "\xEF\xBF\xBD", 0x90 => "\xEF\xBF\xBD", 0x91 => "\xE2\x80\x98", 0x92 => "\xE2\x80\x99", 0x93 => "\xE2\x80\x9C", 0x94 => "\xE2\x80\x9D", 0x95 => "\xE2\x80\xA2", 0x96 => "\xE2\x80\x93", 0x97 => "\xE2\x80\x94", 0x98 => "\xCB\x9C", 0x99 => "\xE2\x84\xA2", 0x9A => "\xC5\xA1", 0x9B => "\xE2\x80\xBA", 0x9C => "\xC5\x93", 0x9D => "\xEF\xBF\xBD", 0x9E => "\xC5\xBE", 0x9F => "\xC5\xB8"];
if ($hex) {
- $codepoint = hexdec($codepoint);
+ // Cap to PHP_INT_MAX to ensure consistent behaviour if $codepoint is so large
+ // it cannot fit into int – just casting float to int might return junk (e.g. a negative number).
+ // If it is so large, `Misc::codepoint_to_utf8` will just return a replacement character.
+ $codepoint = (int) min(hexdec($codepoint), \PHP_INT_MAX);
} else {
- $codepoint = intval($codepoint);
+ // Casting string to int caps at PHP_INT_MAX automatically.
+ $codepoint = (int) $codepoint;
}
if (isset($windows_1252_specials[$codepoint])) {
@@ -579,7 +548,9 @@ class SimplePie_Decode_HTML_Entities
];
for ($i = 0, $match = null; $i < 9 && $this->consume() !== false; $i++) {
- $consumed = substr($this->consumed, 1);
+ // Cast for PHPStan on PHP < 8.0: We consumed as per the loop condition,
+ // so `$this->consumed` is non-empty and the substr offset is valid.
+ $consumed = (string) substr($this->consumed, 1);
if (isset($entities[$consumed])) {
$match = $consumed;
}
diff --git a/wp-includes/SimplePie/library/SimplePie/Enclosure.php b/wp-includes/SimplePie/library/SimplePie/Enclosure.php
index 51e75d3d5e..dd3740ddb8 100644
--- a/wp-includes/SimplePie/library/SimplePie/Enclosure.php
+++ b/wp-includes/SimplePie/library/SimplePie/Enclosure.php
@@ -1,46 +1,9 @@
+ */
class SimplePie_HTTP_Parser extends Parser
{
}
diff --git a/wp-includes/SimplePie/library/SimplePie/IRI.php b/wp-includes/SimplePie/library/SimplePie/IRI.php
index b947d63bf5..7b1e81e2ae 100644
--- a/wp-includes/SimplePie/library/SimplePie/IRI.php
+++ b/wp-includes/SimplePie/library/SimplePie/IRI.php
@@ -1,46 +1,9 @@
name = $name;
$this->link = $link;
$this->email = $email;
diff --git a/wp-includes/SimplePie/src/Cache.php b/wp-includes/SimplePie/src/Cache.php
index 8ed7038b49..587fb1522e 100644
--- a/wp-includes/SimplePie/src/Cache.php
+++ b/wp-includes/SimplePie/src/Cache.php
@@ -1,46 +1,9 @@
>
*/
protected static $handlers = [
- 'mysql' => 'SimplePie\Cache\MySQL',
- 'memcache' => 'SimplePie\Cache\Memcache',
- 'memcached' => 'SimplePie\Cache\Memcached',
- 'redis' => 'SimplePie\Cache\Redis'
+ 'mysql' => Cache\MySQL::class,
+ 'memcache' => Cache\Memcache::class,
+ 'memcached' => Cache\Memcached::class,
+ 'redis' => Cache\Redis::class,
];
/**
@@ -88,7 +49,7 @@ class Cache
* @param Base::TYPE_FEED|Base::TYPE_IMAGE $extension 'spi' or 'spc'
* @return Base Type of object depends on scheme of `$location`
*/
- public static function get_handler($location, $filename, $extension)
+ public static function get_handler(string $location, string $filename, $extension)
{
$type = explode(':', $location, 2);
$type = $type[0];
@@ -104,8 +65,12 @@ class Cache
* Create a new SimplePie\Cache object
*
* @deprecated since SimplePie 1.3.1, use {@see get_handler()} instead
+ * @param string $location
+ * @param string $filename
+ * @param Base::TYPE_FEED|Base::TYPE_IMAGE $extension
+ * @return Base
*/
- public function create($location, $filename, $extension)
+ public function create(string $location, string $filename, $extension)
{
trigger_error('Cache::create() has been replaced with Cache::get_handler() since SimplePie 1.3.1, use the registry system instead.', \E_USER_DEPRECATED);
@@ -117,8 +82,9 @@ class Cache
*
* @param string $type DSN type to register for
* @param class-string $class Name of handler class. Must implement Base
+ * @return void
*/
- public static function register($type, $class)
+ public static function register(string $type, $class)
{
self::$handlers[$type] = $class;
}
@@ -127,12 +93,17 @@ class Cache
* Parse a URL into an array
*
* @param string $url
- * @return array
+ * @return array
*/
- public static function parse_URL($url)
+ public static function parse_URL(string $url)
{
- $params = parse_url($url);
- $params['extras'] = [];
+ $parsedUrl = parse_url($url);
+
+ if ($parsedUrl === false) {
+ return [];
+ }
+
+ $params = array_merge($parsedUrl, ['extras' => []]);
if (isset($params['query'])) {
parse_str($params['query'], $params['extras']);
}
diff --git a/wp-includes/SimplePie/src/Cache/Base.php b/wp-includes/SimplePie/src/Cache/Base.php
index 674fe8c10e..7d6747a0bd 100644
--- a/wp-includes/SimplePie/src/Cache/Base.php
+++ b/wp-includes/SimplePie/src/Cache/Base.php
@@ -1,46 +1,9 @@
|\SimplePie\SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
* @return bool Successfulness
*/
public function save($data);
@@ -90,7 +51,7 @@ interface Base
/**
* Retrieve the data saved to the cache
*
- * @return array Data for SimplePie::$data
+ * @return array Data for SimplePie::$data
*/
public function load();
diff --git a/wp-includes/SimplePie/src/Cache/BaseDataCache.php b/wp-includes/SimplePie/src/Cache/BaseDataCache.php
index 44dbd66d44..60207b0750 100644
--- a/wp-includes/SimplePie/src/Cache/BaseDataCache.php
+++ b/wp-includes/SimplePie/src/Cache/BaseDataCache.php
@@ -1,46 +1,9 @@
*
* @param string $key The key of the item to store.
- * @param array $value The value of the item to store, must be serializable.
+ * @param array $value The value of the item to store, must be serializable.
* @param null|int $ttl Optional. The TTL value of this item. If no value is sent and
* the driver supports TTL then the library may set a default value
* for it or let the driver take care of that.
diff --git a/wp-includes/SimplePie/src/Cache/CallableNameFilter.php b/wp-includes/SimplePie/src/Cache/CallableNameFilter.php
index 0583d0d9b2..e95fa29175 100644
--- a/wp-includes/SimplePie/src/Cache/CallableNameFilter.php
+++ b/wp-includes/SimplePie/src/Cache/CallableNameFilter.php
@@ -1,61 +1,25 @@
callable = $callable;
@@ -78,7 +42,7 @@ final class CallableNameFilter implements NameFilter
* and encodings or longer lengths, but MUST support at least that
* minimum.
*
- * @param string $name The name for the cache will be most likly an url with query string
+ * @param string $name The name for the cache will be most likely an url with query string
*
* @return string the new cache name
*/
diff --git a/wp-includes/SimplePie/src/Cache/DB.php b/wp-includes/SimplePie/src/Cache/DB.php
index a5357b26da..5dac94f407 100644
--- a/wp-includes/SimplePie/src/Cache/DB.php
+++ b/wp-includes/SimplePie/src/Cache/DB.php
@@ -1,54 +1,17 @@
} First item is the serialized data for storage, second item is the unique ID for this item
*/
- protected static function prepare_simplepie_object_for_cache($data)
+ protected static function prepare_simplepie_object_for_cache(\SimplePie\SimplePie $data)
{
$items = $data->get_items();
$items_by_id = [];
diff --git a/wp-includes/SimplePie/src/Cache/DataCache.php b/wp-includes/SimplePie/src/Cache/DataCache.php
index e754132431..02ec59e9c7 100644
--- a/wp-includes/SimplePie/src/Cache/DataCache.php
+++ b/wp-includes/SimplePie/src/Cache/DataCache.php
@@ -1,46 +1,9 @@
*
* @param string $key The key of the item to store.
- * @param array $value The value of the item to store, must be serializable.
+ * @param array $value The value of the item to store, must be serializable.
* @param null|int $ttl Optional. The TTL value of this item. If no value is sent and
* the driver supports TTL then the library may set a default value
* for it or let the driver take care of that.
diff --git a/wp-includes/SimplePie/src/Cache/File.php b/wp-includes/SimplePie/src/Cache/File.php
index 0ffcdf9e25..110a77c43e 100644
--- a/wp-includes/SimplePie/src/Cache/File.php
+++ b/wp-includes/SimplePie/src/Cache/File.php
@@ -1,54 +1,15 @@
location = $location;
$this->filename = $name;
@@ -100,7 +61,7 @@ class File implements Base
/**
* Save data to the cache
*
- * @param array|\SimplePie\SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
+ * @param array|\SimplePie\SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
* @return bool Successfulness
*/
public function save($data)
@@ -119,12 +80,12 @@ class File implements Base
/**
* Retrieve the data saved to the cache
*
- * @return array Data for SimplePie::$data
+ * @return array|false Data for SimplePie::$data
*/
public function load()
{
if (file_exists($this->name) && is_readable($this->name)) {
- return unserialize(file_get_contents($this->name));
+ return unserialize((string) file_get_contents($this->name));
}
return false;
}
@@ -132,7 +93,7 @@ class File implements Base
/**
* Retrieve the last modified time for the cache
*
- * @return int Timestamp
+ * @return int|false Timestamp
*/
public function mtime()
{
diff --git a/wp-includes/SimplePie/src/Cache/Memcache.php b/wp-includes/SimplePie/src/Cache/Memcache.php
index d20f9bfcf6..261bb5d484 100644
--- a/wp-includes/SimplePie/src/Cache/Memcache.php
+++ b/wp-includes/SimplePie/src/Cache/Memcache.php
@@ -1,46 +1,9 @@
*/
protected $options;
@@ -90,7 +51,7 @@ class Memcache implements Base
* @param string $name Unique ID for the cache
* @param Base::TYPE_FEED|Base::TYPE_IMAGE $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
*/
- public function __construct($location, $name, $type)
+ public function __construct(string $location, string $name, $type)
{
$this->options = [
'host' => '127.0.0.1',
@@ -111,7 +72,7 @@ class Memcache implements Base
/**
* Save data to the cache
*
- * @param array|\SimplePie\SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
+ * @param array|\SimplePie\SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
* @return bool Successfulness
*/
public function save($data)
@@ -125,7 +86,7 @@ class Memcache implements Base
/**
* Retrieve the data saved to the cache
*
- * @return array Data for SimplePie::$data
+ * @return array|false Data for SimplePie::$data
*/
public function load()
{
@@ -140,7 +101,7 @@ class Memcache implements Base
/**
* Retrieve the last modified time for the cache
*
- * @return int Timestamp
+ * @return int|false Timestamp
*/
public function mtime()
{
diff --git a/wp-includes/SimplePie/src/Cache/Memcached.php b/wp-includes/SimplePie/src/Cache/Memcached.php
index 8a8d31e7b2..924f31fca5 100644
--- a/wp-includes/SimplePie/src/Cache/Memcached.php
+++ b/wp-includes/SimplePie/src/Cache/Memcached.php
@@ -1,46 +1,10 @@
*/
protected $options;
@@ -87,7 +48,7 @@ class Memcached implements Base
* @param string $name Unique ID for the cache
* @param Base::TYPE_FEED|Base::TYPE_IMAGE $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
*/
- public function __construct($location, $name, $type)
+ public function __construct(string $location, string $name, $type)
{
$this->options = [
'host' => '127.0.0.1',
@@ -107,7 +68,7 @@ class Memcached implements Base
/**
* Save data to the cache
- * @param array|\SimplePie\SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
+ * @param array|\SimplePie\SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
* @return bool Successfulness
*/
public function save($data)
@@ -121,7 +82,7 @@ class Memcached implements Base
/**
* Retrieve the data saved to the cache
- * @return array Data for SimplePie::$data
+ * @return array|false Data for SimplePie::$data
*/
public function load()
{
@@ -164,9 +125,10 @@ class Memcached implements Base
/**
* Set the last modified time and data to NativeMemcached
+ * @param string|false $data
* @return bool Success status
*/
- private function setData($data)
+ private function setData($data): bool
{
if ($data !== false) {
$this->cache->set($this->name . '_mtime', time(), (int)$this->options['extras']['timeout']);
diff --git a/wp-includes/SimplePie/src/Cache/MySQL.php b/wp-includes/SimplePie/src/Cache/MySQL.php
index 1d7986bfc3..73699ad75f 100644
--- a/wp-includes/SimplePie/src/Cache/MySQL.php
+++ b/wp-includes/SimplePie/src/Cache/MySQL.php
@@ -1,46 +1,9 @@
*/
protected $options;
@@ -87,7 +48,7 @@ class MySQL extends DB
* @param string $name Unique ID for the cache
* @param Base::TYPE_FEED|Base::TYPE_IMAGE $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
*/
- public function __construct($location, $name, $type)
+ public function __construct(string $location, string $name, $type)
{
$this->options = [
'user' => null,
@@ -147,7 +108,7 @@ class MySQL extends DB
/**
* Save data to the cache
*
- * @param array|\SimplePie\SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
+ * @param array|\SimplePie\SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
* @return bool Successfulness
*/
public function save($data)
@@ -268,7 +229,7 @@ class MySQL extends DB
/**
* Retrieve the data saved to the cache
*
- * @return array Data for SimplePie::$data
+ * @return array|false Data for SimplePie::$data
*/
public function load()
{
@@ -310,7 +271,7 @@ class MySQL extends DB
$query->bindValue(':feed', $this->id);
if ($query->execute()) {
while ($row = $query->fetchColumn()) {
- $feed['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['entry'][] = unserialize($row);
+ $feed['child'][\SimplePie\SimplePie::NAMESPACE_ATOM_10]['entry'][] = unserialize((string) $row);
}
} else {
return false;
@@ -325,7 +286,7 @@ class MySQL extends DB
/**
* Retrieve the last modified time for the cache
*
- * @return int Timestamp
+ * @return int|false Timestamp
*/
public function mtime()
{
@@ -336,7 +297,7 @@ class MySQL extends DB
$query = $this->mysql->prepare('SELECT `mtime` FROM `' . $this->options['extras']['prefix'] . 'cache_data` WHERE `id` = :id');
$query->bindValue(':id', $this->id);
if ($query->execute() && ($time = $query->fetchColumn())) {
- return $time;
+ return (int) $time;
}
return false;
diff --git a/wp-includes/SimplePie/src/Cache/NameFilter.php b/wp-includes/SimplePie/src/Cache/NameFilter.php
index 19ce7b0a23..9babb41f96 100644
--- a/wp-includes/SimplePie/src/Cache/NameFilter.php
+++ b/wp-includes/SimplePie/src/Cache/NameFilter.php
@@ -1,53 +1,14 @@
*
* @param string $key The key of the item to store.
- * @param array $value The value of the item to store, must be serializable.
+ * @param array $value The value of the item to store, must be serializable.
* @param null|int $ttl Optional. The TTL value of this item. If no value is sent and
* the driver supports TTL then the library may set a default value
* for it or let the driver take care of that.
*
* @return bool True on success and false on failure.
*
- * @throws InvalidArgumentException
+ * @throws InvalidArgumentException&Throwable
* MUST be thrown if the $key string is not a legal value.
*/
public function set_data(string $key, array $value, ?int $ttl = null): bool
@@ -136,7 +98,7 @@ final class Psr16 implements DataCache
*
* @return bool True if the item was successfully removed. False if there was an error.
*
- * @throws InvalidArgumentException
+ * @throws InvalidArgumentException&Throwable
* MUST be thrown if the $key string is not a legal value.
*/
public function delete_data(string $key): bool
diff --git a/wp-includes/SimplePie/src/Cache/Redis.php b/wp-includes/SimplePie/src/Cache/Redis.php
index 5997668c00..3ba0a3ed59 100644
--- a/wp-includes/SimplePie/src/Cache/Redis.php
+++ b/wp-includes/SimplePie/src/Cache/Redis.php
@@ -1,46 +1,10 @@
+// SPDX-License-Identifier: BSD-3-Clause
+
+declare(strict_types=1);
namespace SimplePie\Cache;
@@ -55,8 +19,6 @@ use Redis as NativeRedis;
* connect to redis on `localhost` on port 6379. All tables will be
* prefixed with `simple_primary-` and data will expire after 3600 seconds
*
- * @package SimplePie
- * @subpackage Caching
* @uses Redis
* @deprecated since SimplePie 1.8.0, use implementation of "Psr\SimpleCache\CacheInterface" instead
*/
@@ -72,7 +34,7 @@ class Redis implements Base
/**
* Options
*
- * @var array
+ * @var array
*/
protected $options;
@@ -88,9 +50,9 @@ class Redis implements Base
*
* @param string $location Location string (from SimplePie::$cache_location)
* @param string $name Unique ID for the cache
- * @param Base::TYPE_FEED|Base::TYPE_IMAGE $type Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
+ * @param Base::TYPE_FEED|Base::TYPE_IMAGE|array|null $options Either TYPE_FEED for SimplePie data, or TYPE_IMAGE for image data
*/
- public function __construct($location, $name, $options = null)
+ public function __construct(string $location, string $name, $options = null)
{
//$this->cache = \flow\simple\cache\Redis::getRedisClientInstance();
$parsed = \SimplePie\Cache::parse_URL($location);
@@ -118,6 +80,7 @@ class Redis implements Base
/**
* @param NativeRedis $cache
+ * @return void
*/
public function setRedisClient(NativeRedis $cache)
{
@@ -127,7 +90,7 @@ class Redis implements Base
/**
* Save data to the cache
*
- * @param array|\SimplePie\SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
+ * @param array|\SimplePie\SimplePie $data Data to store in the cache. If passed a SimplePie object, only cache the $data property
* @return bool Successfulness
*/
public function save($data)
@@ -146,7 +109,7 @@ class Redis implements Base
/**
* Retrieve the data saved to the cache
*
- * @return array Data for SimplePie::$data
+ * @return array|false Data for SimplePie::$data
*/
public function load()
{
@@ -161,7 +124,7 @@ class Redis implements Base
/**
* Retrieve the last modified time for the cache
*
- * @return int Timestamp
+ * @return int|false Timestamp
*/
public function mtime()
{
diff --git a/wp-includes/SimplePie/src/Caption.php b/wp-includes/SimplePie/src/Caption.php
index ef72c0b7ac..0c25fa5ce1 100644
--- a/wp-includes/SimplePie/src/Caption.php
+++ b/wp-includes/SimplePie/src/Caption.php
@@ -1,46 +1,9 @@
type = $type;
$this->lang = $lang;
$this->startTime = $startTime;
diff --git a/wp-includes/SimplePie/src/Category.php b/wp-includes/SimplePie/src/Category.php
index d7da8e6831..5439ef4415 100644
--- a/wp-includes/SimplePie/src/Category.php
+++ b/wp-includes/SimplePie/src/Category.php
@@ -1,46 +1,9 @@
term = $term;
$this->scheme = $scheme;
@@ -144,7 +104,7 @@ class Category
* @param bool $strict
* @return string|null
*/
- public function get_label($strict = false)
+ public function get_label(bool $strict = false)
{
if ($this->label === null && $strict !== true) {
return $this->get_term();
diff --git a/wp-includes/SimplePie/src/Content/Type/Sniffer.php b/wp-includes/SimplePie/src/Content/Type/Sniffer.php
index 8c7e089ac5..d1da5fd71f 100644
--- a/wp-includes/SimplePie/src/Content/Type/Sniffer.php
+++ b/wp-includes/SimplePie/src/Content/Type/Sniffer.php
@@ -1,49 +1,16 @@
file = $file;
}
@@ -84,19 +57,21 @@ class Sniffer
*/
public function get_type()
{
- if (isset($this->file->headers['content-type'])) {
- if (!isset($this->file->headers['content-encoding'])
- && ($this->file->headers['content-type'] === 'text/plain'
- || $this->file->headers['content-type'] === 'text/plain; charset=ISO-8859-1'
- || $this->file->headers['content-type'] === 'text/plain; charset=iso-8859-1'
- || $this->file->headers['content-type'] === 'text/plain; charset=UTF-8')) {
+ $content_type = $this->file->has_header('content-type') ? $this->file->get_header_line('content-type') : null;
+ $content_encoding = $this->file->has_header('content-encoding') ? $this->file->get_header_line('content-encoding') : null;
+ if ($content_type !== null) {
+ if ($content_encoding === null
+ && ($content_type === 'text/plain'
+ || $content_type === 'text/plain; charset=ISO-8859-1'
+ || $content_type === 'text/plain; charset=iso-8859-1'
+ || $content_type === 'text/plain; charset=UTF-8')) {
return $this->text_or_binary();
}
- if (($pos = strpos($this->file->headers['content-type'], ';')) !== false) {
- $official = substr($this->file->headers['content-type'], 0, $pos);
+ if (($pos = strpos($content_type, ';')) !== false) {
+ $official = substr($content_type, 0, $pos);
} else {
- $official = $this->file->headers['content-type'];
+ $official = $content_type;
}
$official = trim(strtolower($official));
@@ -130,12 +105,14 @@ class Sniffer
*/
public function text_or_binary()
{
- if (substr($this->file->body, 0, 2) === "\xFE\xFF"
- || substr($this->file->body, 0, 2) === "\xFF\xFE"
- || substr($this->file->body, 0, 4) === "\x00\x00\xFE\xFF"
- || substr($this->file->body, 0, 3) === "\xEF\xBB\xBF") {
+ $body = $this->file->get_body_content();
+
+ if (substr($body, 0, 2) === "\xFE\xFF"
+ || substr($body, 0, 2) === "\xFF\xFE"
+ || substr($body, 0, 4) === "\x00\x00\xFE\xFF"
+ || substr($body, 0, 3) === "\xEF\xBB\xBF") {
return 'text/plain';
- } elseif (preg_match('/[\x00-\x08\x0E-\x1A\x1C-\x1F]/', $this->file->body)) {
+ } elseif (preg_match('/[\x00-\x08\x0E-\x1A\x1C-\x1F]/', $body)) {
return 'application/octet-stream';
}
@@ -149,25 +126,27 @@ class Sniffer
*/
public function unknown()
{
- $ws = strspn($this->file->body, "\x09\x0A\x0B\x0C\x0D\x20");
- if (strtolower(substr($this->file->body, $ws, 14)) === 'file->body, $ws, 5)) === 'file->body, $ws, 7)) === '