Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#49988 closed defect (bug) (fixed)

Incorrect usage of `get_home_url` in PHPUnit tests

Reported by: davidbinda's profile david.binda Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.5 Priority: normal
Severity: normal Version: 4.4
Component: Embeds Keywords:
Focuses: Cc:

Description

The Tests_oEmbed_Response_Data class uses the get_home_url incorrectly on multiple places.

The function is being called with '/' passed to it as first param.

However, the first param should be a $blog_id (either null or int), and is used for a call to switch_to_blog.

So, calling the get_home_url( '/' ) attempts to switch to blog '/' which fails, and URL of the current blog is being returned, but the trailing slash is not being appended.

Which leads to the second issue with those tests - they are actually passing without the trailing slash being added, which I guess is expected (at least accordingly to the code generating actual data: https://core.trac.wordpress.org/browser/trunk/src/wp-includes/embed.php?annotate=blame#L548 )

Fix should be as easy as removing the param passed to get_home_url function call, as it's being done in attached patch.

Attachments (1)

49988.diff (1.4 KB) - added by david.binda 5 years ago.

Download all attachments as: .zip

Change History (3)

@david.binda
5 years ago

#1 @SergeyBiryukov
5 years ago

  • Component changed from General to Embeds
  • Milestone changed from Awaiting Review to 5.5

Thanks for the patch!

It looks like the intention might have been to use home_url() instead. Introduced in [34903].

#2 @SergeyBiryukov
5 years ago

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

In 47615:

Embeds: Fix incorrect usage of get_home_url() in oEmbed tests.

Switch to home_url() for consistency with other tests and to avoid confusion.

Props david.binda.
Fixes #49988.

Note: See TracTickets for help on using tickets.