Make WordPress Core

Ticket #4005: gettext.php.diff

File gettext.php.diff, 1.1 KB (added by Sewar, 18 years ago)

Modified patch for trunk (2.2)

  • gettext.php

     
    287287        $expr = $regs[1];
    288288      else
    289289        $expr = "nplurals=2; plural=n == 1 ? 0 : 1;";
    290       $this->pluralheader = $expr;
     290
     291      // sanitize
     292      $expr = preg_replace(
     293        '@[^a-zA-Z0-9_:;\(\)\?\|\&=!<>+*/\%-]@',
     294        '',
     295        $expr
     296      );
     297
     298      // add parens
     299      // important since PHP's ternary evaluates from left to right
     300      $expr.= ';';
     301      $res= '';
     302      $p= 0;
     303      for ($i= 0; $i < strlen($expr); $i++) {
     304        $ch= $expr[$i];
     305        switch ($ch) {
     306          case '?':
     307            $res.= ' ? (';
     308            $p++;
     309            break;
     310          case ':':
     311            $res.= ') : (';
     312            break;
     313          case ';':
     314            $res.= str_repeat( ')', $p) . ';';
     315            $p= 0;
     316            break;
     317          default:
     318            $res.= $ch;
     319        }
     320      }
     321
     322      $this->pluralheader = $res;
    291323    }
    292324    return $this->pluralheader;
    293325  }