This commit is contained in:
HuangWei 2024-05-07 18:49:23 +02:00 committed by GitHub
commit c3cbca8004
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 1 deletions

1
.gitignore vendored
View File

@ -5,6 +5,7 @@
/vendor/
/data.back/
/constants.local.php
/.idea
.vscode/

View File

@ -1404,6 +1404,45 @@ class SimplePie
return '';
}
/**
* Removes invalid xml 1.0 characters.
*
* link: https://stackoverflow.com/questions/730133/what-are-invalid-characters-in-xml
* xml 1.0 valid charsets: https://www.w3.org/TR/xml/#charsets
* @access public
* @param string $value
* @return string all valid utf-8 characters
*/
public static function stripInvalidXmlCharaters($value)
{
$ret = "";
if (empty($value))
{
return $ret;
}
$length = strlen($value);
for ($i=0; $i < $length; $i++)
{
$current = ord($value[$i]);
if (($current == 0x9) ||
($current == 0xA) ||
($current == 0xD) ||
(($current >= 0x20) && ($current <= 0xD7FF)) ||
(($current >= 0xE000) && ($current <= 0xFFFD)) ||
(($current >= 0x10000) && ($current <= 0x10FFFF)))
{
$ret .= chr($current);
}
else
{
$ret .= sprintf('U+%06X', $current);
}
}
return $ret;
}
/**
* Initialize the feed object
*
@ -1581,9 +1620,10 @@ class SimplePie
{
// Create new parser
$parser = $this->registry->create('Parser');
$validXml = self::stripInvalidXmlCharaters($utf8_data);
// If it's parsed fine
if ($parser->parse($utf8_data, empty($encoding) ? '' : 'UTF-8', $this->permanent_url)) //FreshRSS
if ($parser->parse($validXml, empty($encoding) ? '' : 'UTF-8', $this->permanent_url)) //FreshRSS
{
$this->data = $parser->get_data();
if (!($this->get_type() & ~SIMPLEPIE_TYPE_NONE))