From 35a2045d0c63ebb286184978adc7822d212385ac Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Thu, 5 Dec 2024 23:24:55 +0100 Subject: Merge SimplePie 1.8.1 (#7067) https://github.com/FreshRSS/simplepie/pull/32 --- lib/composer.json | 2 +- lib/simplepie/simplepie/.gitignore | 1 + lib/simplepie/simplepie/CHANGELOG.md | 2 + lib/simplepie/simplepie/phpstan.neon | 67 ------------------------------- lib/simplepie/simplepie/phpstan.neon.dist | 67 +++++++++++++++++++++++++++++++ lib/simplepie/simplepie/src/File.php | 7 ++-- lib/simplepie/simplepie/src/Gzdecode.php | 2 + lib/simplepie/simplepie/src/IRI.php | 17 ++------ lib/simplepie/simplepie/src/SimplePie.php | 2 +- 9 files changed, 81 insertions(+), 86 deletions(-) delete mode 100644 lib/simplepie/simplepie/phpstan.neon create mode 100644 lib/simplepie/simplepie/phpstan.neon.dist diff --git a/lib/composer.json b/lib/composer.json index 2d850a6ab..f80338393 100644 --- a/lib/composer.json +++ b/lib/composer.json @@ -18,7 +18,7 @@ "marienfressinaud/lib_opml": "0.5.1", "phpgt/cssxpath": "dev-master#45f3ac151fc21d459e2515c3aff97cd4bf877bf8", "phpmailer/phpmailer": "6.9.3", - "simplepie/simplepie": "dev-freshrss#88f13f2df1ba17a7432a624d38884b1bd8f60e43" + "simplepie/simplepie": "dev-freshrss#dd86e5e9efb8d082ebd214b81cc5aa746f02fc26" }, "config": { "sort-packages": true, diff --git a/lib/simplepie/simplepie/.gitignore b/lib/simplepie/simplepie/.gitignore index 703d8e51d..94dd5ecc9 100644 --- a/lib/simplepie/simplepie/.gitignore +++ b/lib/simplepie/simplepie/.gitignore @@ -4,6 +4,7 @@ SimplePie.compiled.php bin/ vendor/ composer.lock +phpstan.neon phpunit.xml .php-cs-fixer.cache .phpunit.cache/ diff --git a/lib/simplepie/simplepie/CHANGELOG.md b/lib/simplepie/simplepie/CHANGELOG.md index d097fdad2..69b3dc9df 100644 --- a/lib/simplepie/simplepie/CHANGELOG.md +++ b/lib/simplepie/simplepie/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Use `idn_to_ascii` function instead of `idna_convert` library (requires `intl` extension or a [polyfill](https://github.com/symfony/polyfill-intl-idn)) by @jtojnar in [#785](https://github.com/simplepie/simplepie/pull/785) +- Use native `gzdecode` function instead of internal PHP implementation by @jtojnar in [#882](https://github.com/simplepie/simplepie/pull/882) ### Removed @@ -26,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The method `SimplePie\SimplePie::set_file()` is deprecated, use `SimplePie\SimplePie::set_http_client()` or `SimplePie\SimplePie::set_raw_data()` instead - The method `SimplePie\Sanitize::pass_file_data()` is deprecated, use `SimplePie\Sanitize::set_http_client()` instead - Passing multiple URLs to `SimplePie\SimplePie::set_feed_url()` is deprecated. You can create separate `SimplePie` instance per feed and then use `SimplePie::merge_items()` to get a single list of items. ([#795](https://github.com/simplepie/simplepie/pull/795)) +- The `SimplePie\Gzdecode` class is deprecated. You can use native [`gzdecode`](https://www.php.net/manual/en/function.gzdecode.php) function by @jtojnar in [#882](https://github.com/simplepie/simplepie/pull/882) ## [1.8.0](https://github.com/simplepie/simplepie/compare/1.7.0...1.8.0) - 2023-01-20 diff --git a/lib/simplepie/simplepie/phpstan.neon b/lib/simplepie/simplepie/phpstan.neon deleted file mode 100644 index 5450a9acb..000000000 --- a/lib/simplepie/simplepie/phpstan.neon +++ /dev/null @@ -1,67 +0,0 @@ -parameters: - level: 6 - - paths: - - library/ - - src/ - - tests/ - - ignoreErrors: - # Ignore that only one const exists atm - - - message: "#^Strict comparison using \\!\\=\\= between 'GET' and 'GET' will always evaluate to false\\.$#" - count: 1 - path: src/HTTP/Psr18Client.php - - # SimplePie\Content\Type\Sniffer::__construct(): Parameter $file could be mixed due to BC. - - - message: '(Result of \|\| is always false\.)' - count: 1 - path: src/Content/Type/Sniffer.php - - # Not used since https://github.com/simplepie/simplepie/commit/b2eb0134d53921e75f0fa70b1cf901ed82b988b1 but cannot be removed due to BC. - - '(Constructor of class SimplePie\\Enclosure has an unused parameter \$javascript\.)' - - # Testing legacy dynamic property usage. - - '(Access to an undefined property SimplePie.IRI::\$nonexistent_prop\.)' - - - - message: '(^Strict comparison using === between string and false will always evaluate to false\.$)' - count: 1 - path: src/HTTP/Parser.php - # Only occurs on PHP ≥ 8.0 - reportUnmatched: false - - - - message: '(^Strict comparison using === between string and false will always evaluate to false\.$)' - count: 1 - path: src/IRI.php - # Only occurs on PHP ≥ 8.0 - reportUnmatched: false - - - - message: '(^Parameter #1 \$exception of method PHPUnit\\Framework\\TestCase::expectException\(\) expects class-string, string given\.$)' - - count: 3 - path: tests/Unit/Cache/Psr16Test.php - # Only occurs on PHP ≤ 7.4 - reportUnmatched: false - - - - message: '(^Parameter \$parser of method SimplePie\\Parser::(tag_open|cdata|tag_close)\(\) has invalid type XMLParser\.$)' - - count: 3 - path: src/Parser.php - # Only occurs on PHP ≤ 7.4 - reportUnmatched: false - - - - message: '(^Unable to resolve the template type T in call to method SimplePie\\Registry::get_class\(\)$)' - count: 2 - path: tests/Unit/RegistryTest.php - - # PHPStan stubs bug https://github.com/phpstan/phpstan/issues/8629 - - - message: '(^Access to an undefined property XMLReader::\$\w+\.$)' - # Only occurs on PHP ≥ 8.2 - reportUnmatched: false diff --git a/lib/simplepie/simplepie/phpstan.neon.dist b/lib/simplepie/simplepie/phpstan.neon.dist new file mode 100644 index 000000000..5450a9acb --- /dev/null +++ b/lib/simplepie/simplepie/phpstan.neon.dist @@ -0,0 +1,67 @@ +parameters: + level: 6 + + paths: + - library/ + - src/ + - tests/ + + ignoreErrors: + # Ignore that only one const exists atm + - + message: "#^Strict comparison using \\!\\=\\= between 'GET' and 'GET' will always evaluate to false\\.$#" + count: 1 + path: src/HTTP/Psr18Client.php + + # SimplePie\Content\Type\Sniffer::__construct(): Parameter $file could be mixed due to BC. + - + message: '(Result of \|\| is always false\.)' + count: 1 + path: src/Content/Type/Sniffer.php + + # Not used since https://github.com/simplepie/simplepie/commit/b2eb0134d53921e75f0fa70b1cf901ed82b988b1 but cannot be removed due to BC. + - '(Constructor of class SimplePie\\Enclosure has an unused parameter \$javascript\.)' + + # Testing legacy dynamic property usage. + - '(Access to an undefined property SimplePie.IRI::\$nonexistent_prop\.)' + + - + message: '(^Strict comparison using === between string and false will always evaluate to false\.$)' + count: 1 + path: src/HTTP/Parser.php + # Only occurs on PHP ≥ 8.0 + reportUnmatched: false + + - + message: '(^Strict comparison using === between string and false will always evaluate to false\.$)' + count: 1 + path: src/IRI.php + # Only occurs on PHP ≥ 8.0 + reportUnmatched: false + + - + message: '(^Parameter #1 \$exception of method PHPUnit\\Framework\\TestCase::expectException\(\) expects class-string, string given\.$)' + + count: 3 + path: tests/Unit/Cache/Psr16Test.php + # Only occurs on PHP ≤ 7.4 + reportUnmatched: false + + - + message: '(^Parameter \$parser of method SimplePie\\Parser::(tag_open|cdata|tag_close)\(\) has invalid type XMLParser\.$)' + + count: 3 + path: src/Parser.php + # Only occurs on PHP ≤ 7.4 + reportUnmatched: false + + - + message: '(^Unable to resolve the template type T in call to method SimplePie\\Registry::get_class\(\)$)' + count: 2 + path: tests/Unit/RegistryTest.php + + # PHPStan stubs bug https://github.com/phpstan/phpstan/issues/8629 + - + message: '(^Access to an undefined property XMLReader::\$\w+\.$)' + # Only occurs on PHP ≥ 8.2 + reportUnmatched: false diff --git a/lib/simplepie/simplepie/src/File.php b/lib/simplepie/simplepie/src/File.php index b56fac342..9099c8492 100644 --- a/lib/simplepie/simplepie/src/File.php +++ b/lib/simplepie/simplepie/src/File.php @@ -236,12 +236,11 @@ class File implements Response switch (strtolower(trim($contentEncodingHeader, "\x09\x0A\x0D\x20"))) { case 'gzip': case 'x-gzip': - $decoder = new \SimplePie\Gzdecode($this->body); - if (!$decoder->parse()) { + if (($decompressed = gzdecode($this->body)) === false) { $this->error = 'Unable to decode HTTP "gzip" stream'; $this->success = false; } else { - $this->body = trim($decoder->data); + $this->body = trim($decompressed); } break; @@ -250,7 +249,7 @@ class File implements Response $this->body = $decompressed; } elseif (($decompressed = gzuncompress($this->body)) !== false) { $this->body = $decompressed; - } elseif (function_exists('gzdecode') && ($decompressed = gzdecode($this->body)) !== false) { + } elseif (($decompressed = gzdecode($this->body)) !== false) { $this->body = $decompressed; } else { $this->error = 'Unable to decode HTTP "deflate" stream'; diff --git a/lib/simplepie/simplepie/src/Gzdecode.php b/lib/simplepie/simplepie/src/Gzdecode.php index 6adfc05cc..f331d1dc7 100644 --- a/lib/simplepie/simplepie/src/Gzdecode.php +++ b/lib/simplepie/simplepie/src/Gzdecode.php @@ -11,6 +11,8 @@ namespace SimplePie; * Decode 'gzip' encoded HTTP data * * @link http://www.gzip.org/format.txt + * @link https://www.php.net/manual/en/function.gzdecode.php + * @deprecated since SimplePie 1.9.0, use `gzdecode` function instead. */ class Gzdecode { diff --git a/lib/simplepie/simplepie/src/IRI.php b/lib/simplepie/simplepie/src/IRI.php index 25b342a85..8543b2a52 100644 --- a/lib/simplepie/simplepie/src/IRI.php +++ b/lib/simplepie/simplepie/src/IRI.php @@ -297,19 +297,10 @@ class IRI protected function parse_iri(string $iri) { $iri = trim($iri, "\x20\x09\x0A\x0C\x0D"); - if (preg_match('/^((?P[^:\/?#]+):)?(\/\/(?P[^\/?#]*))?(?P[^?#]*)(\?(?P[^#]*))?(#(?P.*))?$/', $iri, $match)) { - if ($match[1] === '') { - $match['scheme'] = null; - } - if ($match[3] === '') { - $match['authority'] = null; - } - if (!isset($match[6]) || $match[6] === '') { - $match['query'] = null; - } - if (!isset($match[8]) || $match[8] === '') { - $match['fragment'] = null; - } + if (preg_match('/^(?:(?P[^:\/?#]+):)?(:?\/\/(?P[^\/?#]*))?(?P[^?#]*)(?:\?(?P[^#]*))?(?:#(?P.*))?$/', $iri, $match, \PREG_UNMATCHED_AS_NULL)) { + // TODO: Remove once we require PHP ≥ 7.4. + $match['query'] = $match['query'] ?? null; + $match['fragment'] = $match['fragment'] ?? null; return $match; } diff --git a/lib/simplepie/simplepie/src/SimplePie.php b/lib/simplepie/simplepie/src/SimplePie.php index a02138ecd..73d4ed7bd 100644 --- a/lib/simplepie/simplepie/src/SimplePie.php +++ b/lib/simplepie/simplepie/src/SimplePie.php @@ -1520,7 +1520,7 @@ class SimplePie } $this->sanitize->strip_htmltags($tags); if ($encode !== null) { - $this->sanitize->encode_instead_of_strip($tags); + $this->sanitize->encode_instead_of_strip($encode); } } -- cgit v1.2.3