mirror of
git://develop.git.wordpress.org/
synced 2025-04-26 07:02:13 +02:00
Feeds: Avoid fatal error with empty blog_charset
value.
After the SimplePie library was updated to version `1.8.0` in [59141], an edge case has been discovered where a fatal error can encountered if the `blog_charset` option is missing or empty. In `fetch_feed()`, this option is retrieved using `get_option()` instead of `get_bloginfo( ‘charset’ )`. The latter will detect this scenario and apply a default value of `UTF-8` and is already used interchangeably throughout Core. This switches to `get_bloginfo( ‘charset’ )` instead to prevent this edge case. Reviewed by davidbaumwald. Merges [59382] to the 6.7 branch. Props david.binda, davidbaumwald, SergeyBiryukov, sabernhardt, azaozz, peterwilsoncc. Fixes #62354. git-svn-id: https://develop.svn.wordpress.org/branches/6.7@59383 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
1e7e455205
commit
8840acdb4d
@ -842,7 +842,7 @@ function fetch_feed( $url ) {
|
||||
do_action_ref_array( 'wp_feed_options', array( &$feed, $url ) );
|
||||
|
||||
$feed->init();
|
||||
$feed->set_output_encoding( get_option( 'blog_charset' ) );
|
||||
$feed->set_output_encoding( get_bloginfo( 'charset' ) );
|
||||
|
||||
if ( $feed->error() ) {
|
||||
return new WP_Error( 'simplepie-error', $feed->error() );
|
||||
|
51
tests/phpunit/tests/feed/fetchFeed.php
Normal file
51
tests/phpunit/tests/feed/fetchFeed.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* Tests the `fetch_feed` function.
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage UnitTests
|
||||
* @since 6.7.0
|
||||
*
|
||||
* @group feed
|
||||
*/
|
||||
class Tests_Feed_fetchFeed extends WP_UnitTestCase {
|
||||
|
||||
public function set_up() {
|
||||
parent::set_up();
|
||||
|
||||
add_filter( 'pre_http_request', array( $this, 'mocked_rss_response' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 62354
|
||||
*/
|
||||
public function test_empty_charset_does_not_trigger_fatal_error() {
|
||||
add_filter( 'pre_option_blog_charset', '__return_empty_string', 20 );
|
||||
|
||||
$feed = fetch_feed( 'https://wordpress.org/news/feed/' );
|
||||
|
||||
foreach ( $feed->get_items( 0, 1 ) as $item ) {
|
||||
$content = $item->get_content();
|
||||
}
|
||||
|
||||
$this->assertStringContainsString( '<a href="https://learn.wordpress.org/">Learn WordPress</a> is a learning resource providing workshops, quizzes, courses, lesson plans, and discussion groups so that anyone, from beginners to advanced users, can learn to do more with WordPress.', $content );
|
||||
}
|
||||
|
||||
public function mocked_rss_response() {
|
||||
$single_value_headers = array(
|
||||
'Content-Type' => 'application/rss+xml; charset=UTF-8',
|
||||
'link' => '<https://wordpress.org/news/wp-json/>; rel="https://api.w.org/"',
|
||||
);
|
||||
|
||||
return array(
|
||||
'headers' => new WpOrg\Requests\Utility\CaseInsensitiveDictionary( $single_value_headers ),
|
||||
'body' => file_get_contents( DIR_TESTDATA . '/feed/wordpress-org-news.xml' ),
|
||||
'response' => array(
|
||||
'code' => 200,
|
||||
'message' => 'OK',
|
||||
),
|
||||
'cookies' => array(),
|
||||
'filename' => null,
|
||||
);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user