Make WordPress Core

Opened 19 months ago

Closed 14 months ago

Last modified 14 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 = "www.example.com/article"

$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 14 months ago.

Download all attachments as: .zip

Change History (8)

#1 @dd32
19 months 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( 'www.example.com/article' );
array(1) {
  'path' =>
  string(23) "www.example.com/article"
}

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.

https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-includes/rewrite.php#L498-L507

#2 @SergeyBiryukov
19 months 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], [52799], and are continued in #55656.

Moving this ticket to the milestone for visibility as well.

Version 1, edited 19 months ago by SergeyBiryukov (previous) (next) (diff)

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


19 months ago
#3

  • Keywords has-patch added

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

Trac ticket: https://core.trac.wordpress.org/ticket/55753

#4 @lopo
19 months 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
14 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
14 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:


14 months ago
#7

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.