WordPress.org

Make WordPress Core

Opened 14 months ago

Last modified 14 months ago

#44759 new defect (bug)

Percent-encoded unicode characters in CPT rewrite slug prevent finding the CPTs on the front-end

Reported by: mnelson4 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords:
Focuses: Cc:
PR Number:

Description

If you register a custom post type whose rewrite slug has percent-encoded unicode characters in it, the posts can't be found on the front-end.

Eg

<?php
function register_unicode_cpt()
{
    register_post_type(
        'unicode_cpt',
        array(
            'label' => 'unicode-cpts',
            'public' => true,
            'rewrite' => array(
                'slug' => '%E6%BC%A2%E8%AA%9E%3B' // doesn't work
                // 'rewrite_slug' => '漢語' // works
            )
        )
    );
}
add_action('init','register_unicode_cpt');

Seems to initially work fine, the ugly percent-encoded unicode characters don't appear in the post editor (Eg https://drive.google.com/a/eventespresso.com/file/d/1d1j6skbgxrA7IJocGvYi5UMQ_Xw3sCrV/view?usp=drivesdk), but when I go to view the CPT, I'm being redirected to the homepage, (or, when my homepage displays latest posts, I'm seeing those without being redirected).

It seems some code needs to recognize percent-encoded rewrite slugs are the same as the unicode character ones.

The workaround is to use the unicode characters directly, which is technically against the RFC (see https://stackoverflow.com/questions/2742852/unicode-characters-in-urls/2742985#2742985)

Change History (1)

#1 @mnelson4
14 months ago

  • Summary changed from percent encoded unicode characters in post type rewrite slug to Percent-encoded unicode characters in CPT rewrite slug prevent finding the CPTs on the front-end
Note: See TracTickets for help on using tickets.