Canonical: Ensure redirect query keys are URL encoded.
This prevents an infinite redirect loop when a request containing URL-encoded characters triggers `is_404()`. Props soulseekah, wrwrwr0. Fixes #43745. git-svn-id: https://develop.svn.wordpress.org/trunk@45133 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
639f038dae
commit
65e057daa2
@ -388,7 +388,10 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) {
|
||||
}
|
||||
}
|
||||
|
||||
$_parsed_query = rawurlencode_deep( $_parsed_query );
|
||||
$_parsed_query = array_combine(
|
||||
rawurlencode_deep( array_keys( $_parsed_query ) ),
|
||||
rawurlencode_deep( array_values( $_parsed_query ) )
|
||||
);
|
||||
$redirect_url = add_query_arg( $_parsed_query, $redirect_url );
|
||||
}
|
||||
|
||||
|
@ -213,4 +213,24 @@ class Tests_Canonical extends WP_Canonical_UnitTestCase {
|
||||
// Todo: Endpoints (feeds, trackbacks, etc), More fuzzed mixed query variables, comment paging, Home page (Static)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 43745
|
||||
*/
|
||||
public function test_utf8_query_keys_canonical() {
|
||||
$p = self::factory()->post->create(
|
||||
array(
|
||||
'post_type' => 'page',
|
||||
)
|
||||
);
|
||||
update_option( 'show_on_front', 'page' );
|
||||
update_option( 'page_on_front', $p );
|
||||
|
||||
$this->go_to( get_permalink( $p ) );
|
||||
|
||||
$url = redirect_canonical( add_query_arg( '%D0%BA%D0%BE%D0%BA%D0%BE%D0%BA%D0%BE', 1, site_url( '/' ) ), false );
|
||||
$this->assertNull( $url );
|
||||
|
||||
delete_option( 'page_on_front' );
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user