Index: trunk/extensions/RegexFun/RegexFun.php |
— | — | @@ -289,7 +289,7 @@ |
290 | 290 | return self::msgInvalidRegex( $pattern ); |
291 | 291 | } |
292 | 292 | |
293 | | - // set these infos after pattern validation/correction |
| 293 | + // set these infos only if valid, pattern still contains special flags though |
294 | 294 | self::setLastPattern( $parser, $pattern ); |
295 | 295 | self::setLastSubject( $parser, $subject ); |
296 | 296 | } |
— | — | @@ -308,7 +308,7 @@ |
309 | 309 | * @param array $allowedSpecialFlags all special flags that should be handled, by default 'e' and 'r'. |
310 | 310 | */ |
311 | 311 | public static function doPregReplace( |
312 | | - &$pattern, |
| 312 | + $pattern, // not by value in here! |
313 | 313 | $replacement, |
314 | 314 | $subject, |
315 | 315 | $limit = -1, |
— | — | @@ -319,31 +319,37 @@ |
320 | 320 | ) |
321 | 321 | ) { |
322 | 322 | static $lastPattern = null; |
323 | | - static $lastFlags = null; |
| 323 | + static $activePattern = null; |
324 | 324 | static $specialFlags = null; |
325 | 325 | |
326 | 326 | /* |
327 | 327 | * cache validated pattern and use it as long as nothing has changed, this makes things |
328 | 328 | * faster in case we do a lot of stuff with the same regex. |
329 | 329 | */ |
330 | | - if( $lastPattern === null || $lastPattern !== $pattern |
331 | | - || $lastFlags !== implode( ',', $allowedSpecialFlags ) |
332 | | - ) { |
| 330 | + if( $lastPattern === null || $lastPattern !== $pattern ) { |
| 331 | + // remember pattern without validation |
| 332 | + $lastPattern = $pattern; |
| 333 | + |
333 | 334 | // if allowed special flags change, we have to validate again^^ |
334 | 335 | $lastFlags = implode( ',', $allowedSpecialFlags ); |
335 | 336 | |
336 | 337 | // validate regex and get special flags 'e' and 'r' if given: |
337 | 338 | if( ! self::validateRegex( $pattern, $specialFlags ) ) { |
338 | 339 | // invalid regex! |
| 340 | + $lastPattern = null; |
339 | 341 | return false; |
340 | 342 | } |
| 343 | + // set validated pattern as active one |
| 344 | + $activePattern = $pattern; |
341 | 345 | |
342 | 346 | // filter unwanted special flags: |
343 | | - $allowedSpecialFlags = array_flip( $allowedSpecialFlags ); |
| 347 | + $allowedSpecialFlags = array_flip( $allowedSpecialFlags ); |
344 | 348 | $specialFlags = array_intersect_key( $specialFlags, $allowedSpecialFlags ); |
345 | | - |
346 | | - $lastPattern = $pattern; |
347 | 349 | } |
| 350 | + else { |
| 351 | + // set last validated pattern without flags 'e' and 'r' |
| 352 | + $pattern = $activePattern; |
| 353 | + } |
348 | 354 | |
349 | 355 | |
350 | 356 | // FLAG 'e' (parse replace after match) handling: |
— | — | @@ -658,9 +664,12 @@ |
659 | 665 | if( isset( $parser->mExtRegexFun['lastMatches'] ) ) { |
660 | 666 | |
661 | 667 | // last matches are set to false in case last regex was in replace mode! Get them on demand: |
662 | | - if( $parser->mExtRegexFun['lastMatches'] === false ) { |
| 668 | + if( $parser->mExtRegexFun['lastMatches'] === false ) { |
| 669 | + // first, validate pattern to remove special flags! |
| 670 | + $pattern = self::getLastPattern( $parser ); |
| 671 | + self::validateRegex( $pattern ); |
663 | 672 | preg_match( |
664 | | - self::getLastPattern( $parser ), |
| 673 | + $pattern, |
665 | 674 | self::getLastSubject( $parser ), |
666 | 675 | $parser->mExtRegexFun['lastMatches'] |
667 | 676 | ); |