Opened 9 years ago
Last modified 4 weeks ago
#41791 new defect (bug)
Unicode + add_permastruct breaks rewrite rules
| Reported by: | mikejolley | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Rewrite Rules | Version: | 4.9 |
| Severity: | normal | Keywords: | has-patch dev-feedback |
| Cc: | Focuses: |
Description
This was reported here https://github.com/woocommerce/woocommerce/issues/16673
To recreate the issue, create a taxonomy with a cyrillic name such as Сертификат. View the taxonomy archive. You'll see no results; it will go to the homepage rather than an archive.
In WooCommerce you can recreate this by creating an attribute (Product > Attributes) with a cyrillic name, and enabling the 'archive', assigning a term from this taxonomy to a product, and trying to view products by that term.
I managed to trace it back to the add_permastruct. The struct is added with unicode % encoded characters. When the rewrite rules are processed, it thinks these are placeholders so the matches variables do not align. See this screenshot for clarity:
https://www.dropbox.com/s/5vztnfm6895488a/query%20is%20wrong.png?dl=0
Notice all the $matches? Compare to a working taxonomy:
https://www.dropbox.com/s/24zyr5v7taw7b60/correct.png?dl=0
This can be fixed by using urldecode when adding the permastruct. I don't know if this has side effects but it worked in testing.
Patch to follow.
Attachments (2)
Change History (7)
This ticket was mentioned in PR #12863 on WordPress/wordpress-develop by @sainathpoojary.
6 weeks ago
#4
This PR intercepts the permastruct inside WP_Rewrite::add_permastruct() and decodes the URL-encoded slug back into standard UTF-8 text before saving it.
To ensure we don't accidentally corrupt real rewrite tags (where %ca in %category% could be decoded by a naive urldecode), we use a preg_replace_callback that strictly decodes only uppercase hex strings ([0-9A-F]). WordPress's URL encoding always uses uppercase, while built-in rewrite tags use lowercase, making this a safe and robust fix.
Trac ticket: #41791
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Fix for 41791