Make WordPress Core

Opened 3 weeks ago

Closed 10 days ago

#63652 closed defect (bug) (fixed)

_oembed_rest_pre_serve_request() can erroneously return a string value

Reported by: sergeybiryukov's profile SergeyBiryukov Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.9 Priority: normal
Severity: normal Version: 4.4
Component: Embeds Keywords: good-first-bug has-patch
Focuses: Cc:

Description

_oembed_rest_pre_serve_request() is attached to the rest_pre_serve_request filter and is supposed to return a boolean value.

However, there is a code path where it returns a string via get_status_header_desc(), see the second conditional:

// Embed links inside the request.
$data = $server->response_to_data( $result, false );

if ( ! class_exists( 'SimpleXMLElement' ) ) {
	status_header( 501 );
	die( get_status_header_desc( 501 ) );
}

$result = _oembed_create_xml( $data );

// Bail if there's no XML.
if ( ! $result ) {
	status_header( 501 );
	return get_status_header_desc( 501 );
}

Since the function is expected to output a string, I think return should be replaced with die here, to match the first conditional.

Introduced in [35436] / #34207.

Change History (5)

This ticket was mentioned in PR #9178 on WordPress/wordpress-develop by @abcd95.


3 weeks ago
#1

  • Keywords has-patch added; needs-patch removed

This ticket was mentioned in Slack in #core-test by oglekler. View the logs.


10 days ago

#3 @oglekler
10 days ago

@SergeyBiryukov I cannot figure out how to test it, and due to this, I am now adding needs-testing. If you think it should be tested, please provide testing instructions. If you think it doesn't need it, please proceed. Thank you!

#4 @SergeyBiryukov
10 days ago

I think this is good to go, thanks!

#5 @SergeyBiryukov
10 days ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 60443:

Embeds: Correct error handling in _oembed_rest_pre_serve_request().

Since the function is supposed to output a string and only return a boolean value, this commit ensures that an error message is properly displayed, bringing consistency with a similar fragment a few lines above.

Follow-up to [35436].

Props abcd95, oglekler, SergeyBiryukov.
Fixes #63652.

Note: See TracTickets for help on using tickets.