Skip to content

Commit 9f7fc54

Browse files
Canonical: Check if the author parameter is a string in redirect_canonical().
This avoids a PHP warning or error when viewing an author on the front end, while an array is passed as `$_GET['author']`. Follow-up to [12034], [12040], [12202]. Props david.binda, antonvlasenko, azaozz, SergeyBiryukov. Fixes #60059. git-svn-id: https://develop.svn.wordpress.org/trunk@57232 602fd350-edb4-49c9-b593-d223f7449a82
1 parent da1f881 commit 9f7fc54

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

src/wp-includes/canonical.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,9 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) {
316316
$redirect['query'] = remove_query_arg( 'year', $redirect['query'] );
317317
}
318318
}
319-
} elseif ( is_author() && ! empty( $_GET['author'] ) && preg_match( '|^[0-9]+$|', $_GET['author'] ) ) {
319+
} elseif ( is_author() && ! empty( $_GET['author'] )
320+
&& is_string( $_GET['author'] ) && preg_match( '|^[0-9]+$|', $_GET['author'] )
321+
) {
320322
$author = get_userdata( get_query_var( 'author' ) );
321323

322324
if ( false !== $author

tests/phpunit/tests/canonical.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ public function data_canonical() {
206206
array( '/?author=%d', '/author/canonical-author/' ),
207207
// array( '/?author=%d&year=2008', '/2008/?author=3'),
208208
// array( '/author/canonical-author/?year=2008', '/2008/?author=3'), // Either or, see previous testcase.
209+
array( '/author/canonical-author/?author[1]=hello', '/author/canonical-author/?author[1]=hello', 60059 ),
209210

210211
// Feeds.
211212
array( '/?feed=atom', '/feed/atom/' ),

0 commit comments

Comments
 (0)