From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1362 invoked from network); 5 May 2003 17:48:19 -0000 Received: from unknown (HELO monty-python.gnu.org) (199.232.76.173) by sources.redhat.com with SMTP; 5 May 2003 17:48:19 -0000 Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 19Ck4I-0006t2-05 for listarch-gnats-devel@sources.redhat.com; Mon, 05 May 2003 13:48:02 -0400 Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 19Ck42-0006qd-00 for help-gnats@gnu.org; Mon, 05 May 2003 13:47:46 -0400 Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 19Ck2X-0005n3-00 for help-gnats@gnu.org; Mon, 05 May 2003 13:46:13 -0400 Received: from teapot.netman.dk ([193.88.72.6]) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 19Ck1d-0005em-00 for help-gnats@gnu.org; Mon, 05 May 2003 13:45:17 -0400 Received: from teapot.netman.dk (localhost [127.0.0.1]) by teapot.netman.dk (8.12.8/8.12.8) with ESMTP id h45Hj5uX478343; Mon, 5 May 2003 19:45:05 +0200 (MEST) Received: (from lh@localhost) by teapot.netman.dk (8.12.8/8.12.8/Submit) id h45Hj4I9478334; Mon, 5 May 2003 19:45:04 +0200 (MEST) Date: Mon, 05 May 2003 17:48:00 -0000 From: Lars Henriksen To: Yngve Svendsen Message-ID: <20030505174504.GA477164@teapot.netman.dk> References: <5.2.1.1.0.20030429212316.00d0c430@ms-etro01-01.norway.sun.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5.2.1.1.0.20030429212316.00d0c430@ms-etro01-01.norway.sun.com> User-Agent: Mutt/1.4i cc: "'help-gnats@gnu.org'" cc: Dieperink Alwin Subject: Re: Categories containing "++" make gnatsweb crash X-BeenThere: help-gnats@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: General discussion about GNU GNATS List-Help: List-Post: List-Subscribe: , List-Archive: Sender: help-gnats-bounces+listarch-gnats-devel=sources.redhat.com@gnu.org Errors-To: help-gnats-bounces+listarch-gnats-devel=sources.redhat.com@gnu.org X-SW-Source: 2003-q2/txt/msg00039.txt.bz2 On Tue, Apr 29, 2003 at 09:39:54PM +0200, Yngve Svendsen wrote: > At 15:28 20.01.2003 +0100, Dieperink Alwin wrote: > >Hello, > > > >When categories contain a "++" in their name, gnatsweb crashes with the > >following error: > > (snip) > > >There are several solutions: > >1) restrict the use of special characters in category names and correct > >"categories" > >2) correct the use of grep in gnatsweb. > >3) ... > > > >My preference goes actually to the first solution. > > Thanks for reporting this. I ended up modifying the code to avoid the use > of grep -- it wasn't a good idea to use it anyway since it is an > unnecessarily expensive operation in this context. And moreover, I do not > want to assume anything about allowed characters in GNATS category names. Here is the code: Index: gnatsweb.pl =================================================================== RCS file: /cvsroot/gnatsweb/gnatsweb/gnatsweb.pl,v retrieving revision 1.120 retrieving revision 1.121 diff -c -r1.120 -r1.121 *** gnatsweb.pl 8 Jan 2003 13:04:17 -0000 1.120 --- gnatsweb.pl 29 Apr 2003 19:25:35 -0000 1.121 [snip] *** 1577,1588 **** if (fieldinfo ($_, 'fieldtype') eq 'enum') { my $default = $fields{$_}; # Check whether field value is a known enumeration value. ! if (!(grep /^$default$/, @$values)) ! { ! push(@$values, 'unknown') if (!grep /^unknown$/, @$values); ! $default = 'unknown'; ! } print popup_or_scrolling_menu($_, $values, $default), "\n\n"; } --- 1577,1595 ---- if (fieldinfo ($_, 'fieldtype') eq 'enum') { my $default = $fields{$_}; + my $found = 0; # Check whether field value is a known enumeration value. ! foreach(@$values) ! { ! next if ($_ ne $default); ! $found = 1; ! last; ! } ! unless ($found) ! { ! push(@$values, 'unknown'); ! $default = 'unknown'; ! } print popup_or_scrolling_menu($_, $values, $default), "\n\n"; } I agree that assumptions about characters should be avoided and that the foreach-construction does this, but please lecture me: is perl-grep particularly expensive?. I have another comment, though. If the field value isn't a known enumeration value, the value 'unknown' is inserted in the enumeration array and made the default value for display. But in my original code the insertion of 'unknown' only happened if it wasn't already there (the second grep operation above). The reason is that 'unknown' may be a perfectly valid enumeration value (and if it is already there, we don't want to insert it a second time). E.g. I have the following entry in the responsible file: unknown:The name is not in the responsible file - use "view" to see it.:gnats-admin If you edit a PR with an unknown responsible, the descriptive text is then diplayed as a guide to the user. Here is a suggestion for a modified foreach-loop: my $found = 0; my $nopush = 0; # Check whether field value is a known enumeration value. foreach(@$values) { $found = 1 if $_ eq $default; $nopush = 1 if $_ eq 'unknown'; } unless ($found) { push(@$values, 'unknown') unless $nopush; $default = 'unknown'; } Lars Henriksen _______________________________________________ Help-gnats mailing list Help-gnats@gnu.org http://mail.gnu.org/mailman/listinfo/help-gnats