From 68da7e4e751db8e5557e8a4c58bda3d8d1e770c3 Mon Sep 17 00:00:00 2001 From: Alex Schroeder Date: Mon, 12 Oct 2015 15:09:49 +0200 Subject: [PATCH] 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. --- t/search.t | 2 +- t/upgrade-files.t | 4 ++-- wiki.pl | 15 ++++++++++----- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/t/search.t b/t/search.t index 9363c6f4..52ef6af4 100644 --- a/t/search.t +++ b/t/search.t @@ -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. diff --git a/t/upgrade-files.t b/t/upgrade-files.t index 5045003a..78214a01 100644 --- a/t/upgrade-files.t +++ b/t/upgrade-files.t @@ -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; diff --git a/wiki.pl b/wiki.pl index d20eb844..520d0555 100755 --- a/wiki.pl +++ b/wiki.pl @@ -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 {