--- gnatsweb_v40.pl     Thu Apr 15 20:42:03 2004
+++ gnatsweb.pl Fri Apr 16 11:50:23 2004
@@ -1313,7 +1313,7 @@
   my($cmd, $pr, $include_return_url) = @_;
   my $url = $q->url() . "?cmd=$cmd&database=$global_prefs{'database'}";
   $url .= "&pr=$pr" if $pr;
-  $url .= "&return_url=" . $q->escape($q->self_url())
+  $url .= "&return_url=" . $q->escape(strip_empty_params($q->self_url()))
         if $include_return_url;
   return $url;
 }
@@ -2388,6 +2388,7 @@
   my(@query_results) = @_;
   my $displaydate = $q->param('displaydate');
   my $reversesort = $q->param('reversesort');
+  my $queryname = $q->param('queryname');

   my $num_matches = scalar(@query_results);
   my $heading = sprintf("%s %s found",
@@ -2421,11 +2422,7 @@
     }
     $whichfield++;

-    # strip empty params out of self_url().  in a gnats db with many
-    # fields, the url query-string will become very long.  this is a
-    # problem, since IE5 truncates query-strings at ~2048 characters.
-    my ($query_string) = $q->self_url() =~ m/^[^?]*\?(.*)$/;
-    $query_string =~ s/(\w|-)+=;//g;
+    my ($query_string) = strip_empty_params($q->self_url() =~ m/^[^?]*\?(.*)$/);

     my $href = $script_name . '?' . $query_string;
     print "\n<th><a href=\"$href\">$_</a></th>\n";
@@ -2506,11 +2503,7 @@
         $q->end_form();

   # Provide a URL which someone can use to bookmark this query.
-  my $url = $q->self_url();
-  # strip empty params out of $url.  in a gnats db with many
-  # fields, the url query-string will become very long.  this is a
-  # problem, since IE5 truncates query-strings at ~2048 characters.
-  $url =~ s/(\w|-)+=;//g;
+  my $url = strip_empty_params($q->self_url());

   print "\n<p>",
         qq{<a href="$url">View for bookmarking</a>},
@@ -2523,27 +2516,31 @@
   print qq{<a href="$url">Reverse sort order</a>},
         "</p>";

-  # Allow the user to store this query.  Need to repeat params as hidden
-  # fields so they are available to the 'store query' handler.
-  print $q->start_form(), hidden_debug();
-  foreach ($q->param())
-  {
-    # Ignore certain params.
-    next if /^(cmd|queryname)$/;
-    print $q->hidden($_), "\n";
-  }
-  print "\n<table>\n",
-        "<tr>\n",
-        "<td>Remember this query as:</td>\n",
-        "<td>",
-        $q->textfield(-name=>'queryname', -size=>25),
-        "</td>\n<td>";
-  # Note: include hidden 'cmd' so user can simply press Enter w/o clicking.
-  print $q->hidden(-name=>'cmd', -value=>'store query', -override=>1),
-        $q->submit('cmd', 'store query'),
-        $q->hidden('return_url', $q->self_url()),
-        "\n</td>\n</tr>\n</table>",
-        $q->end_form();
+  if (!$queryname)
+    {
+    # Allow the user to store this query.  Need to repeat params as hidden
+    # fields so they are available to the 'store query' handler.
+    print $q->start_form(), hidden_debug();
+    foreach ($q->param())
+    {
+      # Ignore certain params.
+      next if /^(cmd|queryname)$/;
+      print $q->hidden($_), "\n";
+    }
+    print "\n<table>\n",
+          "<tr>\n",
+          "<td>Remember this query as:</td>\n",
+          "<td>",
+          $q->textfield(-name=>'queryname', -size=>25),
+          "</td>\n<td>";
+    # Note: include hidden 'cmd' so user can simply press Enter w/o clicking.
+
+    print $q->hidden(-name=>'cmd', -value=>'store query', -override=>1),
+          $q->submit('cmd', 'store query'),
+          $q->hidden('return_url', strip_empty_params($q->self_url())),
+          "\n</td>\n</tr>\n</table>",
+          $q->end_form();
+    }
 }

 # store_query -
@@ -2581,12 +2578,7 @@

   # Don't save certain params.
   $q->delete('cmd');
-  my $query_string = $q->query_string();
-
-  # strip empty params out of $query_string.  in a gnats db with many
-  # fields, the query-string will become very long, and may exceed the
-  # 4K limit for cookies.
-  $query_string =~ s/\w+=;//g;
+  my $query_string = strip_empty_params($q->query_string());

   if (length($query_string . $global_cookie_path . "gnatsweb-query-$queryname") > 4050) {
     # this cookie is going to be longer than 4K, so we'll have to punt
@@ -2674,7 +2666,7 @@
           $q->start_form(),
          hidden_debug(),
           "<td>",
-          $q->hidden('return_url', $q->self_url()),
+          $q->hidden('return_url', strip_empty_params($q->self_url())),
           hidden_db(),
           $q->submit('cmd', 'delete stored query'),
           "<td>&nbsp;<td>",
@@ -2907,6 +2899,16 @@
   return ($LEVEL_TO_CODE{$access_level} >= $LEVEL_TO_CODE{'edit'});
 }

+# strip empty params out of url().  in a gnats db with many
+# fields, the url query-string will become very long.  this is a
+# problem, since IE5 truncates query-strings at ~2048 characters.
+sub strip_empty_params
+  {
+  my ($url) = @_;
+  $url =~ s/(\w|-)+=;//g;
+  return $url;
+  }
+
 sub main_page
 {
   my $page = 'Main';
@@ -4158,7 +4160,7 @@
     # We don't have username/database; give login page then
     # redirect to the url they really want (self_url).
     print_header();
-    login_page($q->self_url());
+    login_page(strip_empty_params($q->self_url()));
     exit();
   }
