From: mozilla%colinogilvie.co.uk <> Date: Mon, 9 Jan 2006 03:52:07 +0000 (+0000) Subject: Bug 101380: Newlines, nulls, leading/trailing spaces are getting into summaries X-Git-Tag: bugzilla-2.16.11~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9c480f386e5824b5adc2bfe03c1f7b970436a921;p=thirdparty%2Fbugzilla.git Bug 101380: Newlines, nulls, leading/trailing spaces are getting into summaries Patch by Paul and Colin Ogilvie ; r/a=justdave --- diff --git a/checksetup.pl b/checksetup.pl index c74a760c04..4e5395a766 100755 --- a/checksetup.pl +++ b/checksetup.pl @@ -3010,6 +3010,25 @@ if (GetFieldDef("logincookies", "hostname")) { AddField("logincookies", "ipaddr", "varchar(40) NOT NULL"); } +# Fixup for Bug 101380 +# "Newlines, nulls, leading/trailing spaces are getting into summaries" + +my $controlchar_bugs = + $dbh->selectall_arrayref("SELECT short_desc, bug_id FROM bugs WHERE " . + "'short_desc' REGEXP '[[:cntrl:]]'"); +if (@$controlchar_bugs) +{ + print 'Cleaning control characters from bug summaries...'; + foreach (@$controlchar_bugs) { + my ($short_desc, $bug_id) = @$_; + print " $bug_id..."; + $short_desc = clean_text($short_desc); + $dbh->do("UPDATE bugs SET short_desc = ? WHERE bug_id = ?", + undef, $short_desc, $bug_id); + } + print " done.\n"; +} + # If you had to change the --TABLE-- definition in any way, then add your # differential change code *** A B O V E *** this comment. # diff --git a/globals.pl b/globals.pl index fc3764e561..1bb80d70b3 100644 --- a/globals.pl +++ b/globals.pl @@ -1574,6 +1574,12 @@ sub trim { return $str; } +sub clean_text { + my ($dtext) = shift; + $dtext =~ s/[\x00-\x1F\x7F]+/ /g; # change control characters to spaces + return trim($dtext); +} + ############################################################################### # Global Templatization Code diff --git a/post_bug.cgi b/post_bug.cgi index 10c3fb5e85..0f4267e7ab 100755 --- a/post_bug.cgi +++ b/post_bug.cgi @@ -100,7 +100,8 @@ if (!$::FORM{'component'}) { exit; } -if (!defined $::FORM{'short_desc'} || trim($::FORM{'short_desc'}) eq "") { +$::FORM{'short_desc'} = clean_text($::FORM{'short_desc'}); +if (!defined $::FORM{'short_desc'} || $::FORM{'short_desc'} eq "") { DisplayError("You must enter a summary for this bug."); exit; } diff --git a/process_bug.cgi b/process_bug.cgi index 07b93129e0..e1d37c0e5b 100755 --- a/process_bug.cgi +++ b/process_bug.cgi @@ -125,6 +125,8 @@ if ( Param("usetargetmilestone") ) { CheckFormFieldDefined(\%::FORM, 'target_milestone'); } +$::FORM{'short_desc'} = clean_text($::FORM{'short_desc'}); + # # This function checks if there is a comment required for a specific # function and tests, if the comment was given.