WordPress.org

Make WordPress Core

Changeset 45133


Ignore:
Timestamp:
04/08/2019 01:09:01 AM (3 years ago)
Author:
pento
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/canonical.php

    r43571 r45133  
    389389        }
    390390
    391         $_parsed_query = rawurlencode_deep( $_parsed_query );
     391        $_parsed_query = array_combine(
     392            rawurlencode_deep( array_keys( $_parsed_query ) ),
     393            rawurlencode_deep( array_values( $_parsed_query ) )
     394        );
    392395        $redirect_url  = add_query_arg( $_parsed_query, $redirect_url );
    393396    }
  • trunk/tests/phpunit/tests/canonical.php

    r42343 r45133  
    214214        );
    215215    }
     216
     217    /**
     218     * @ticket 43745
     219     */
     220    public function test_utf8_query_keys_canonical() {
     221        $p = self::factory()->post->create(
     222            array(
     223                'post_type' => 'page',
     224            )
     225        );
     226        update_option( 'show_on_front', 'page' );
     227        update_option( 'page_on_front', $p );
     228
     229        $this->go_to( get_permalink( $p ) );
     230
     231        $url = redirect_canonical( add_query_arg( '%D0%BA%D0%BE%D0%BA%D0%BE%D0%BA%D0%BE', 1, site_url( '/' ) ), false );
     232        $this->assertNull( $url );
     233
     234        delete_option( 'page_on_front' );
     235    }
    216236}
Note: See TracChangeset for help on using the changeset viewer.