Sfoglia il codice sorgente

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).
Alexandre Alapetite 9 mesi fa
parent
commit
7c57f38008
2 ha cambiato i file con 9 aggiunte e 4 eliminazioni
  1. 1 1
      lib/composer.json
  2. 8 3
      lib/simplepie/simplepie/src/File.php

+ 1 - 1
lib/composer.json

@@ -14,7 +14,7 @@
         "marienfressinaud/lib_opml": "0.5.1",
         "phpgt/cssxpath": "v1.3.0",
         "phpmailer/phpmailer": "6.10.0",
-        "simplepie/simplepie": "dev-freshrss#f644950102ef4d4ab6e811db6ee9416d7151484a"
+        "simplepie/simplepie": "dev-freshrss#2f0417355a702c678c237eac5ffc273863301a80"
     },
     "config": {
         "sort-packages": true,

+ 8 - 3
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");
+        }
     }
 
     /**