Opened 7 years ago
Last modified 7 years ago
#44759 new defect (bug)
Percent-encoded unicode characters in CPT rewrite slug prevent finding the CPTs on the front-end
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Posts, Post Types | Keywords: | |
Focuses: | Cc: |
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)