Use warnings

search.t: Using braces without escaping them in regular expressions
trigges a warning. wiki.pl will now quotemeta the replacement string
when highlighting changes.

upgrade-files.t: Only remove the old UseMod directory if it actually
exists in order to fix some warnings.

wiki.pl: only reading the log file when open actually succeeded in order
to fix some warnings.
This commit is contained in:
Alex Schroeder
2015-10-12 15:09:49 +02:00
parent c38ff25cda
commit 68da7e4e75
3 changed files with 13 additions and 8 deletions

View File

@@ -131,7 +131,7 @@ test_page(get_page('SearchAndReplace'), 'xfuu and \[xa\]bar.');
test_page(get_page('search=xfuu replace=/fuu/ pwd=foo'), '1 pages found'); # not two ab!
test_page(get_page('SearchAndReplace'), '/fuu/ and \[xa\]bar.');
test_page(get_page('search=/fuu/ replace={{fuu}} pwd=foo'), '1 pages found');
test_page(get_page('SearchAndReplace'), '{{fuu}} and \[xa\]bar.');
test_page(get_page('SearchAndReplace'), '\{\{fuu\}\} and \[xa\]bar.');
# Check headers especially the quoting of non-ASCII characters.

View File

@@ -18,8 +18,8 @@ $_ = 'nocgi';
require 't/usemod-1.0.4.pl';
# wipe /tmp/mywikidb!
use File::Path;
rmtree([$UseModWiki::DataDir]);
use File::Path qw(remove_tree);
remove_tree($UseModWiki::DataDir) if -d $UseModWiki::DataDir;
package UseModWiki;

15
wiki.pl
View File

@@ -31,6 +31,9 @@
package OddMuse;
use strict;
use warnings;
no warnings 'numeric';
no warnings 'uninitialized';
use utf8; # in case anybody ever adds UTF8 characters to the source
use CGI qw/-utf8/;
use CGI::Carp qw(fatalsToBrowser);
@@ -45,7 +48,7 @@ our ($ScriptName, $FullUrl, $PageDir, $TempDir, $LockDir, $KeepDir, $RssDir,
$UrlPattern, $FullUrlPattern, $InterSitePattern,
$UrlProtocols, $ImageExtensions, $LastUpdate,
%LockOnCreation, %PlainTextPages, %AdminPages,
@MyAdminCode, @MyFooters, @MyFormChanges, @MyInitVariables, @MyMacros, @MyMaintenance,
@MyAdminCode, @MyFormChanges, @MyInitVariables, @MyMacros, @MyMaintenance,
$DocumentHeader, %HtmlEnvironmentContainers, $FS, $Counter, @Debugging);
# Internal variables:
@@ -1497,10 +1500,12 @@ sub GetRcLines { # starttime, hash of seen pages to use as a second return value
my %match = $filterOnly ? map { $_ => 1 } SearchTitleAndBody($filterOnly) : ();
my %following = ();
my @result = ();
my $ts;
# check the first timestamp in the default file, maybe read old log file
open(my $F, '<:encoding(UTF-8)', $RcFile);
my $line = <$F>;
my ($ts) = split(/$FS/, $line); # the first timestamp in the regular rc file
if (open(my $F, '<:encoding(UTF-8)', $RcFile)) {
my $line = <$F>;
($ts) = split(/$FS/, $line); # the first timestamp in the regular rc file
}
if (not $ts or $ts > $starttime) { # we need to read the old rc file, too
push(@result, GetRcLinesFor($RcOldFile, $starttime, \%match, \%following));
}
@@ -3408,7 +3413,7 @@ sub DoSearch {
print $q->start_div({-class=>'content replacement'});
@results = ReplaceAndSave($re, UnquoteHtml($replacement));
foreach (@results) {
PrintSearchResult($_, $replacement || $re);
PrintSearchResult($_, quotemeta($replacement || $re)); # the replacement is not a valid regex
}
}
} else {