[wp-trac] [WordPress Trac] #36812: WP_Rewrite removes regex groups, should replace with non-capturing

WordPress Trac noreply at wordpress.org
Wed May 11 05:23:45 UTC 2016


#36812: WP_Rewrite removes regex groups, should replace with non-capturing
---------------------------+-----------------------------
 Reporter:  cvedovini      |      Owner:
     Type:  defect (bug)   |     Status:  new
 Priority:  normal         |  Milestone:  Awaiting Review
Component:  Rewrite Rules  |    Version:  4.5.2
 Severity:  normal         |   Keywords:
  Focuses:                 |
---------------------------+-----------------------------
 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);
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/36812>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list