public inbox for gnats-devel@sourceware.org
 help / color / mirror / Atom feed
* Gnatsweb: stripping empty fields in URLs
@ 2004-04-16 17:57 Dieperink Alwin
  0 siblings, 0 replies; only message in thread
From: Dieperink Alwin @ 2004-04-16 17:57 UTC (permalink / raw)
  To: 'help-gnats@gnu.org'; +Cc: 'Yngve Svendsen'

[-- Attachment #1: Type: text/plain, Size: 686 bytes --]

Hello,

As explained in gnatsweb.pl, the size of the query string is limited by the
browser to approx. 2K. That's why we want to strip the empty parameters.

This patch brings following changes to this:
- correct a bug where the striping was incorrect
- added a function to do the striping
- use that function everywhere, even where the striping was not done yet

With these changes, the URLs are now correct and as short as possible, even
in the return_url parameter.

This patch also removes the ability to store a query when the displayed
result is already the result of a stored query. This also leads to longer
query strings and could make the cookie unusable.

Regards
-- Alwin



[-- Attachment #2: strip_empty_params.patch --]
[-- Type: application/octet-stream, Size: 5290 bytes --]

--- 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();
   }

[-- Attachment #3: Type: text/plain, Size: 139 bytes --]

_______________________________________________
Help-gnats mailing list
Help-gnats@gnu.org
http://mail.gnu.org/mailman/listinfo/help-gnats

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-04-16  9:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-16 17:57 Gnatsweb: stripping empty fields in URLs Dieperink Alwin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).