Make WordPress Core

Opened 2 years ago

Closed 22 months ago

Last modified 22 months ago

#55753 closed defect (bug) (fixed)

PHP deprecated notice from parse_url() in url_to_postid()

Reported by: lagiosdi's profile lagios.di Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.1 Priority: normal
Severity: normal Version: 5.9
Component: Permalinks Keywords: has-patch
Focuses: Cc:

Description (last modified by dd32)

line 500 at wp 5.9.3
example input:
url = ""

$url_host = str_replace( 'www.', '', parse_url( $url, PHP_URL_HOST ) );

make warning:
Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in wp-includes/rewrite.php on line 500

Attachments (1)

54364-props.png (373.7 KB) - added by SergeyBiryukov 22 months ago.

Download all attachments as: .zip

Change History (8)

#1 @dd32
2 years ago

  • Description modified (diff)
  • Summary changed from parse_url at url_to_postid to PHP deprecated notice from parse_url() in url_to_postid()

Hi @lagiosdi,

The provided input to the function is invalid in this case, as it's not a value which can be parsed as a URL by PHP, and as a result is unlikely to generate a valid return value.

> parse_url( '' );
array(1) {
  'path' =>
  string(23) ""

The function should probably bail early with invalid input like this though, rather than attempting to continue, as it'll return on the line after this deprecated notice anyway.

#2 @SergeyBiryukov
2 years ago

  • Component changed from General to Permalinks
  • Milestone changed from Awaiting Review to 6.1
  • Owner set to SergeyBiryukov
  • Status changed from new to accepted

Hi there, welcome back to WordPress Trac! Thanks for the ticket.

Some related fixes were previously done in #53635 and #54730, see [51606], [51622], [51626], [51629], [51630], and are continued in #55656.

Moving this ticket to the milestone for visibility as well.

Version 0, edited 2 years ago by SergeyBiryukov (next)

This ticket was mentioned in PR #2760 on WordPress/wordpress-develop by enricobattocchi.

2 years ago

  • Keywords has-patch added

Add a safeguard to parse_url() output in case of malformed URL.

Trac ticket:

#4 @lopo
2 years ago

  • Version set to 5.9

I applied a simple safeguard to the output from parse_url() to make sure we're passing a string to str_replace().

We can't bail out early as @dd32 suggested because url_to_postid() currently supports arguments such as '/example/examp', as the unit tests show so I'm just preventing the deprecation here.

Setting version to 5.9 since it's the first version "beta-supporting" PHP 8.1

#5 @mukesh27
22 months ago

  • Keywords changes-requested added

@lopo Thanks for the PR. I left one suggestion.

@SergeyBiryukov Is this ticket on your radar for 6.1?

#6 @SergeyBiryukov
22 months ago

  • Keywords changes-requested removed
  • Resolution set to fixed
  • Status changed from accepted to closed

This appears to be resolved in [54364] / #55656 while working on #56681, but I forgot that there was an existing ticket for this issue. Sorry for that! I have updated the props list for that commit in the Core Props tool on make/core to include the props from this ticket: 54364-props.png.

SergeyBiryukov commented on PR #2760:

22 months ago

Thanks for the PR! This was fixed in r54364 as part of the efforts to get a passing build on PHP 8.1.

The props for that commit are now updated to include the props from this PR, see comment 6 on the ticket.

Note: See TracTickets for help on using tickets.