aboutsummaryrefslogtreecommitdiff
path: root/lib/simplepie
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2025-06-25 16:37:41 +0200
committerGravatar GitHub <noreply@github.com> 2025-06-25 16:37:41 +0200
commit7c57f38008136202ba7b38e3154ac87be4eefb68 (patch)
tree8fb1c8856579e3f1ae880ae5d3e64ccc18339572 /lib/simplepie
parent42aeecb5ed6f7e89c795dca0f96ba6497f3e349e (diff)
Fix feeds encoded in UTF-16LE (#7691)
* Fix feeds encoded in UTF-16LE Fix https://github.com/FreshRSS/FreshRSS/issues/7690 https://github.com/FreshRSS/simplepie/pull/40 The final character `>` of a feed is encoded as `3E00` in UTF-16LE, so calling `trim()` was removing the `\x00`, breaking the multibyte encoding and making the feed invalid. Upstream PR https://github.com/simplepie/simplepie/pull/916 * Trim body for all paths https://github.com/FreshRSS/simplepie/pull/42 https://github.com/simplepie/simplepie/pull/917 Slight refactor of https://github.com/simplepie/simplepie/pull/916 (https://github.com/FreshRSS/simplepie/pull/40) to cover all paths. Missing paths included the fsock method without gzip (e.g. deflate or plain).
Diffstat (limited to 'lib/simplepie')
-rw-r--r--lib/simplepie/simplepie/src/File.php11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/simplepie/simplepie/src/File.php b/lib/simplepie/simplepie/src/File.php
index 6f5f37c3c..a6a444f56 100644
--- a/lib/simplepie/simplepie/src/File.php
+++ b/lib/simplepie/simplepie/src/File.php
@@ -162,7 +162,7 @@ class File implements Response
$parser = new \SimplePie\HTTP\Parser($responseHeaders, true);
if ($parser->parse()) {
$this->set_headers($parser->headers);
- $this->body = trim($parser->body);
+ $this->body = $parser->body;
$this->status_code = $parser->status_code;
if ((in_array($this->status_code, [300, 301, 302, 303, 307]) || $this->status_code > 307 && $this->status_code < 400) && ($locationHeader = $this->get_header_line('location')) !== '' && $this->redirects < $redirects) {
$this->redirects++;
@@ -246,7 +246,7 @@ class File implements Response
$this->error = 'Unable to decode HTTP "gzip" stream';
$this->success = false;
} else {
- $this->body = trim($decompressed);
+ $this->body = $decompressed;
}
break;
@@ -288,11 +288,16 @@ class File implements Response
$this->error = sprintf('file "%s" is not readable', $url);
$this->success = false;
} else {
- $this->body = trim($filebody);
+ $this->body = $filebody;
$this->status_code = 200;
}
$this->on_http_response();
}
+ if ($this->success) {
+ // (Leading) whitespace may cause XML parsing errors so we trim it,
+ // but we must not trim \x00 to avoid breaking BOM or multibyte characters
+ $this->body = trim($this->body, " \n\r\t\v");
+ }
}
/**