User:AnomieBOT/source/tasks/PERTableUpdater.pm: Difference between revisions

Content deleted Content added
AnomieBOT (talk | contribs)
Updating published sources: PERTableUpdater: * Try to escape unmatched left-braces that Perl complains about when processing blacklist.
AnomieBOT (talk | contribs)
Updating published sources: PERTableUpdater: * Only log about bad regexes once per day.
Line 92:
}
$api->store->{"ver"} = 2;
}
 
# Flush warnings daily
my $ts = time;
$ts -= $ts % 86400;
if ( ($api->store->{'warnedBadRegexDate'} // 0) < $ts) {
$api->store->{'warnedBadRegex'} = {};
$api->store->{'warnedBadRegexDate'} = $ts;
}
 
Line 137 ⟶ 145:
my $tmp = $re;
$re=~s#(?<!\\[a-zA-Z])(?<!\\)\{(?!\d+(?:,\d*)?})#\\{#g;
$apiself->warnwarnBadRegex( $api, "Escaped left-braces in regex (old): $tmp" ) if $tmp ne $re;
$apiself->warnwarnBadRegex( $api, "Escaped left-braces in regex (new): $re" ) if $tmp ne $re;
 
# Validate each line, in case someone screws up the blacklist page
Line 145 ⟶ 153:
};
if ( $@ ) {
$apiself->warnwarnBadRegex( $api, "Ignoring bad regex '$re' in $page\n");
next;
}
Line 457 ⟶ 465:
$t=0 if $t<0;
return $t;
}
 
sub warnBadRegex {
my ($self, $api, $msg) = @_;
 
my $warned = $api->store->{'warnedBadRegex'};
return if exists( $warned->{$msg} );
$warned->{$msg} = 1;
$api->store->{'warnedBadRegex'} = $warned;
$api->warn( $msg );
}