Re: too many 'changed' entries

Dirk Schenkewitz <[email protected]>
Newsgroups gmane.comp.bug-tracking.gnats.general
Message-ID <[email protected]>
Hi All,

I finally found out the reason & solved my own problem.
Thank you very much, Mel, for turning me in the right direction!

Mel Hatzis wrote:
> 
> On 03/27/2003 06:04 AM, Dirk Schenkewitz submitted:
>
> > ...
>
> I noticed this too. In my case, I setup a field as 'required' and
> it wasn't working via gnatsweb, because gnatsweb was inserting a
> newline (thereby making the field look like it had a value).
> 
> I fixed it by changing the 'fix_multiline_val' sub, as follows:
> 
> sub fix_multiline_val
> {
>   my $val = shift;
>   $val =~ s/\r\n?/\n/g;
>   $val .= "\n" unless $val =~ /\n$/;
>   if ($val =~ /^\s*$/)
>   {
>     # don't allow whitespace values to circumvent 'required' fields
>     $val = "";
>   }
>   $val;
> }
> 
> This basically prevents whitespace only values from being entered
> as the (multiline) field value which I consider to be a good fix.
> 
> This should help you in the case where a newly created PR is edited
> for the first time - since this is when gnatsweb will add the
> newline, thereby changing the field and adding a change log to the
> audit trail.
> 
> Hope this helps.

It did, although not completely. Now I know that I caused the problem
by myself, by adding "-wrap=>'hard'" to the edit-fields. This was done
to preserve the format of an PR, esp. user-added line-breaks. Without
it I found no way to distinguish between user-added and gnatsweb-added
line-breaks. But it caused the following strange behaviour:
 - a soft linebreak was inserted as a single <CR><LF> sequence.
 - a hard (user-added) linebreak was inserted as <CR><LF><CR><LF><CR><LF>.

I found no way to avoid that. Finally I changed 'fix_multiline_val'
into the attached one. From then on, everything worked like I wanted:
 - Soft linebreaks do not make it into the PR
 - Hard linebreaks go into the PR as-is.

I send this to the list just in case someone else wants this behaviour
or stumbles over it. It's not a Gnatsweb bug but merely a perl-cgi bug.
But it seems the only way to get rid of it is a special version of
'fix_multiline_val'.

Have fun.
	dirk

-- 
Dirk Schenkewitz 

InterFace AG                 fon: +49 (0)89 / 610 49 - 126
Leipziger Str. 16            fax: +49 (0)89 / 610 49 - 83
D-82008 Unterhaching         
http://www.interface-ag.de   mailto:[email protected]

_______________________________________________
Help-gnats mailing list
[email protected]
http://mail.gnu.org/mailman/listinfo/help-gnats
fix_multiline_val.pl (application/x-perl, 847 B)
sub fix_multiline_val
{
  my $val = shift;

  # remove all '\r's, they are not needed:
  $val =~ s/\r//g;

  # remove soft breaks, add one blank but only when neccesary:
  $val =~ s/([ \t])[\n]([^\n])/$1$2/g;
  $val =~ s/([^\n])[\n]([ \t])/$1$2/g;
  $val =~ s/([^\n\s])[\n]([^\n\s])/$1 $2/g;

  # and now some special cases to keep up to three empty lines:
  $val =~ s/([^\n])\n{3}([^\n])/$1\n$2/g;	# just a line break
  $val =~ s/([^\n])\n{5}([^\n])/$1\n\n$2/g;	# one empty line
  $val =~ s/([^\n])\n{7}([^\n])/$1\n\n\n$2/g;	# two empty lines
  $val =~ s/([^\n])\n{9,}([^\n])/$1\n\n\n\n$2/g; # 3, but never more !

  $val =~ s/\n+$//g;	# remove all linefeeds at the end of the field
  $val .= "\n";		# then add one again

  if ($val =~ /^\s*$/)
  {
    # don't allow whitespace values to circumvent 'required' fields
    $val = "";
  }
  $val;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.