Fix: Guard against wp_parse_url() returning false in Pagination_Helper#23061
Open
ProjectEli wants to merge 1 commit intoYoast:trunkfrom
Open
Fix: Guard against wp_parse_url() returning false in Pagination_Helper#23061ProjectEli wants to merge 1 commit intoYoast:trunkfrom
ProjectEli wants to merge 1 commit intoYoast:trunkfrom
Conversation
…) returns false in pagination-helper.phper Adds a guard clause to handle the case where wp_parse_url() returns false (e.g., malformed URLs), preventing a fatal TypeError on PHP 8.x. Fixes Yoast#23057
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
When
wp_parse_url()receives a malformed URL (e.g.,http:///caused by a missingHostheader), it returnsfalseinstead of an array. The subsequentarray_key_exists('query', false)call throws aTypeErroron PHP 8.x, resulting in a fatal error.Summary
This PR can be summarized in the following changelog entry:
TypeErroroccurred inpagination-helper.phpwhenwp_parse_url()returnedfalsedue to a malformed URL (e.g., requests without aHostheader on Bitnami WordPress environments).Relevant technical choices:
if ( ! is_array( $url_parts ) ) return $url;) before accessing the parsed URL array. This is the minimal, defensive fix that preserves existing behavior for all valid URLs while gracefully handling the edge case.Test instructions
Test instructions for the acceptance test before the PR gets merged
This PR can be acceptance tested by following these steps:
wp-config.phpto setWP_HOMEto a malformed URL such ashttp:///(simulating a missingHostheader scenario).TypeErroris thrown atpagination-helper.php:74.WP_HOMEto its normal value and confirm pagination still works correctly on archive pages.Relevant test scenarios
Console should show no PHP errors or warnings after the fix is applied.
Test instructions for QA when the code is in the RC
Impact check
This PR affects the following parts of the plugin, which may require extra testing:
src/helpers/pagination-helper.php— specifically theget_paginated_url()method. Regression testing should confirm that normal pagination (rel next/prev) continues to work on archive and paginated pages.Quality assurance
Innovation
Fixes #23057