#51056 closed defect (bug) (fixed)
Fetch_feed parsing of permalinks triggers simplepie preg_match warnings
Reported by: | litemotiv | Owned by: | iandunn |
---|---|---|---|
Milestone: | 5.6.1 | Priority: | high |
Severity: | critical | Version: | 5.5 |
Component: | External Libraries | Keywords: | php8 has-patch has-unit-tests |
Focuses: | rest-api | Cc: |
Description
Tested with 2 sites running within the same 5.5 multisite network:
$feed = fetch_feed(<other WP site RSS URL>); $items = $feed->get_items(0,2); foreach ($items as $item) echo $item->get_permalink();
PHP warnings:
*6667000 FastCGI sent in stderr: "PHP message: PHP Warning: preg_match() expects parameter 2 to be string, array given in /media/www/multisite/wp-includes/class-simplepie.php on line 2620 PHP message: PHP Warning: preg_match() expects parameter 2 to be string, array given in /media/www/multisite/wp-includes/class-simplepie.php on line 2620 PHP message: PHP Warning: preg_match() expects parameter 2 to be string, array given in /media/www/multisite/wp-includes/class-simplepie.php on line 2620 PHP message: PHP Warning: preg_match() expects parameter 2 to be string, array given in /media/www/multisite/wp-includes/class-simplepie.php on line 2620 [ ... ]
The permalinks are parsed okay and are returned.
Attachments (1)
Change History (21)
This ticket was mentioned in PR #496 on WordPress/wordpress-develop by inc2734.
4 years ago
#1
- Keywords has-patch added
#2
@
4 years ago
I've recreated it too. It happens when you use the feed on the archive page. I created a pull request.
https://github.com/WordPress/wordpress-develop/pull/496
#3
@
4 years ago
I've been able to reproduce the issue as well. As it was already mentioned, the issue is easily reproducible when attempting to parse a category feed on a WordPress install.
What happens is that WordPress sends 2 link HTTP headers in the response via rest_output_link_header
function (one for the api.wp.org and one alternate for application/json leading to the rest api endpoint).
SimplePie used by the fetch_feed
function, however, expects the multiple headers of the same name being joined together and separated by a comma ( a notation described by rfc8288 ). SimplePie itself handles this in https://github.com/simplepie/simplepie/blob/a72e1dfafe7870affdae3edf0d9a494e4fa31bc6/library/SimplePie/HTTP/Parser.php#L254,L263
However the SimplePie's SimplePie_File
class is being overloaded by WP_SimplePie_File
via SimplePie::set_file_class
in https://core.trac.wordpress.org/browser/trunk/src/wp-includes/feed.php?rev=48435#L805 , which does not handle the headers in the same way (multiple headers of the same name are being stored in an array).
IMHO, it would be better to fix the issue in WP_SimplePie_File
, not touching the wp-includes/class-simplepie.php file, which is a copy of an external project, which does not suffer from the issue.
Further, the SimplePie_File
class makes sure that only the last content-type
header is being used. While this works as expected in the current implementation of the WP_SimplePie_File
class, I believe that it might be a good idea to cover that with a unit test.
#4
@
4 years ago
I forgot to add, that the warning is new, as it was introduced in terms of the SimplePie update in WP 5.5 ( r47733 )
This ticket was mentioned in Slack in #core by sergey. View the logs.
4 years ago
This ticket was mentioned in Slack in #core by helen. View the logs.
4 years ago
This ticket was mentioned in Slack in #core by hellofromtonya. View the logs.
4 years ago
#11
@
4 years ago
- Focuses rest-api added
- Keywords php8 added
- Owner set to iandunn
- Priority changed from normal to high
- Severity changed from normal to critical
- Status changed from new to assigned
Bringing over keywords/etc from #51956.
Additional props from that ticket: NicolasKulka, hellofromTonya, mbabker, skithund , SergeyBiryukov, desrosj, timothyblynjacobs
This ticket was mentioned in PR #819 on WordPress/wordpress-develop by iandunn.
4 years ago
#12
- Keywords has-unit-tests added
SimplePie combines multiple values for a HTTP header into a comma-separated string, but WP_SimplePie_File
was leaving them as an array. That leads to a fatal error in PHP 8.
Trac ticket: https://core.trac.wordpress.org/ticket/51056
#15
follow-up:
↓ 16
@
4 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
Reopening for backport to 5.6.1.
@desrosj, @SergeyBiryukov, is one of you able to look at that?
ticket:51956#comment:17 has an mu-plugin that helps w/ manual testing.
#17
@
4 years ago
Ah, thanks for catching that!
I'll fix it, and then go ahead and backport since you've already reviewed.
hellofromtonya commented on PR #496:
4 years ago
#20
Merged in changeset https://core.trac.wordpress.org/changeset/49803
Display warning when using category/tag archives feeds.
https://core.trac.wordpress.org/ticket/51056