Opened 10 years ago
Last modified 6 years ago
#36812 new defect (bug)
WP_Rewrite removes regex groups, should replace with non-capturing
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | 4.5.2 |
| Component: | Rewrite Rules | Keywords: | |
| Focuses: | Cc: |
Description
I have got that plugin which adds a rewrite tag like so:
add_rewrite_tag('%lang%', '(en|fr)', 'lang=');
One can then customize the permalinks and add the post's language anywhere in the url.
The problem is that, at one point, the WP_Rewrite class adds rules for attachment and on line 1112 of class-wp-rewrite.php it simply gets rid of all the parenthesis in the regex.
So, if I configure the permalink to be /%postname%/lang/%lang%/ the resulting regex for the rewrite rule is:
[^/]+/lang/en|fr|zh/attachment/([^/]+)/?$
which is a totally different rule than expected, where anything/lang/en is matched as an attachment page when it really shouldn't be.
Instead the regex should be:
[^/]+/lang/(?:en|fr|zh)/attachment/([^/]+)/?$
The code on line 1112 of class-wp-rewrite.php should be replaced with:
$submatchbase = str_replace( '(', '(?:', $match);
Note: See
TracTickets for help on using
tickets.
+1 I just ran into this exact same issue. It is preventing me from properly creating a structure for a rebuild of a site that used month names instead of month numbers in their post permalinks.
I worked around it by defining my own tokens for
(and), and then replaced those in "post_rewrite_rules"The only way I could work around it right now is to define my own placeholders for '(' and ')' and replace those in a
post_rewrite_rulesfilter. (Note: I couldn't use non-capturing groups because those throw off the queryvar matching, it puts the next tag in my non-capturing tags query var).