r39114 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r39113‎ | r39114 | r39115 >
Date:01:32, 11 August 2008
Author:brion
Status:old
Tags:
Comment:
* (bug 15099) Bad regexes make the at least some of the blacklist get ignored
Lines with "\" at the end would silently break both that and the following line in the batch, without triggering the overall parse errors.
Added a specific check for this case to skip the bad lines when building, and to check for them and report a warning during editing.
Modified paths:
  • /trunk/extensions/SpamBlacklist/SpamBlacklist_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SpamBlacklist/SpamBlacklist_body.php
@@ -413,6 +413,13 @@
414414 $regexEnd = ($batchSize > 0 ) ? ')/Si' : ')/i';
415415 $build = false;
416416 foreach( $lines as $line ) {
 417+ if( substr( $line, -1, 1 ) == "\\" ) {
 418+ // Final \ will break silently on the batched regexes.
 419+ // Skip it here to avoid breaking the next line;
 420+ // warnings from getBadLines() will still trigger on
 421+ // edit to keep new ones from floating in.
 422+ continue;
 423+ }
417424 // FIXME: not very robust size check, but should work. :)
418425 if( $build === false ) {
419426 $build = $line;
@@ -497,13 +504,22 @@
498505 */
499506 static function getBadLines( $lines ) {
500507 $lines = SpamRegexBatch::stripLines( $lines );
 508+
 509+ $badLines = array();
 510+ foreach( $lines as $line ) {
 511+ if( substr( $line, -1, 1 ) == "\\" ) {
 512+ // Final \ will break silently on the batched regexes.
 513+ $badLines[] = $line;
 514+ }
 515+ }
 516+
501517 $regexes = SpamRegexBatch::buildRegexes( $lines );
502518 if( SpamRegexBatch::validateRegexes( $regexes ) ) {
503 - // No problems!
504 - return array();
 519+ // No other problems!
 520+ return $badLines;
505521 }
506522
507 - $badLines = array();
 523+ // Something failed in the batch, so check them one by one.
508524 foreach( $lines as $line ) {
509525 $regexes = SpamRegexBatch::buildRegexes( array( $line ) );
510526 if( !SpamRegexBatch::validateRegexes( $regexes ) ) {

Status & tagging log