#55753 closed defect (bug) (fixed)
PHP deprecated notice from parse_url() in url_to_postid()
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 6.1 | Priority: | normal |
| Severity: | normal | Version: | 5.9 |
| Component: | Permalinks | Keywords: | has-patch |
| Focuses: | Cc: |
Description (last modified by )
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)
Change History (8)
#1
@
4 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()
#2
@
4 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
This ticket was mentioned in PR #2760 on WordPress/wordpress-develop by enricobattocchi.
4 years 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
@
4 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
@
3 years 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
@
3 years 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.
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