[wp-trac] Re: [WordPress Trac] #4005: php-gettext's plural forms parsing is broken for nplurals>2

WordPress Trac wp-trac at lists.automattic.com
Thu Mar 29 02:02:09 GMT 2007


#4005: php-gettext's plural forms parsing is broken for nplurals>2
------------------------------+---------------------------------------------
 Reporter:  moeffju           |        Owner:  ryan 
     Type:  defect            |       Status:  new  
 Priority:  high              |    Milestone:  2.2  
Component:  i18n              |      Version:  2.1.2
 Severity:  normal            |   Resolution:       
 Keywords:  has-patch commit  |  
------------------------------+---------------------------------------------
Comment (by moeffju):

 While your string passes the sanitizing regex, the code is never actually
 run since in the next step (in select_string()), all 'n's are replaced
 with the value of `$n`, which breaks the `priNt`. echo would probably
 work. Changing the regex to:

 {{{
         $expr= preg_replace(
                 '@[^plurasno0-9:;\(\)\?\|\&=!<>+*/\%-]@',
                 '',
                 $expr
         );
 }}}

 ought to fix that, too. (The additional 'o' in the char range is for
 malformed files using 'or' instead of '|``|'; I also removed the
 underscore.)

 Alternatively, you could sanitize the plurals= part separately and strip
 semicolons and all chars but 'n' on the RHS of the assignment:

 {{{
 if (preg_match('/^\s*nplurals\s*=\s*(\d+)\s*;\s*plural=(.*)$/', $expr,
 $matches)) {
         $nplurals= preg_replace( '@[^0-9]@', '', $matches[1] );
         $plural= preg_replace( '@[^n0-9:\(\)\?\|\&=!<>+*/\%-]@', '',
 $matches[2] );
         $expr= 'nplurals='.$nplurals.';plural='.$plural;
 }
 else {
 //malformed expression, use default
 }
 }}}

 I'll submit a new patch using the second alternative.

-- 
Ticket URL: <http://trac.wordpress.org/ticket/4005#comment:11>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list