Re: Seeming bug in URI::URL

Aaron Sherman (ajs@openmarket.com)
Tue, 17 Oct 1995 10:14:43 -0400


Creating yet more object levels just to deal with queries might not be
the right thing to do in terms of performance. The changes that I've
made so far to deal with this are in the following patch.

This patch make query escaping special, in that it deals with escaping
urls that may already be escaped. It also shuts off the initial
unescaping of queries.

Happy hacking!


--- URL.pm.old	Tue Oct 17 09:26:18 1995
+++ URL.pm	Tue Oct 17 10:11:20 1995
@@ -551,8 +551,11 @@
 
 sub _esc_query {
     my($self, $text, @unsafe) = @_;
+    my $ok_for_query = '^\w\$.+!*\'(),{}\[\]|\\^~`<>\#%"&=-';
     $text =~ s/ /+/g;   # RFC1630
-    my $text = $self->escape($text, @unsafe);
+    $text = $self->escape($text,$ok_for_query);
+    $text =~ s/ \% (?! [a-fA-F0-9]{2} ) /\%25/gx;
+    return $text;
 }
 
 
@@ -607,7 +610,7 @@
     if ($u =~ s/\?(.*)//){      # '+' -> ' ' for queries (RFC1630)
         my $query = $1;
         $query =~ s/\+/ /g;
-        $self->{'query'}  = $self->unescape($query)
+        $self->{'query'}  = $query;
     }
     # 2.4.5
     $self->{'params'} = $self->unescape($1) if $u =~ s/;(.*)//;
@@ -668,13 +671,14 @@
     # use @ here to avoid undef warnings and allow $self->escape
     # to use optimised pattern if no override has been set.
     my @unsafe = shift || $self->unsafe || ();
+
     my($path, $params, $query)
         = @{$self}{ qw(path params query) };
     my $u = '';
-    $u .=     $self->_esc_path($path,    @unsafe) if $path;
+    $u .=     $self->_esc_path($path,    @unsafe) if $path ne '';
     $u = "/$u" unless $u =~ m:^/:; # see comment in _parse 2.4.6
-    $u .= ";".$self->_esc_params($params,@unsafe) if $params;
-    $u .= "?".$self->_esc_query($query,  @unsafe) if $query;
+    $u .= ";".$self->_esc_params($params,@unsafe) if $params ne '';
+    $u .= "?".$self->_esc_query($query,  @unsafe_for_query) if $query ne '';
 
     # rfc 1808 says:
     #    Note that the fragment identifier (and the "#" that precedes 

--
Aaron Sherman <ajs@ajs.com>		B4 f w+ c kv s+(--)v r p
I-Kinetics, Inc.			Pager: (508)545-0584
1 NE Executive Park			Fax:   (617)270-4979
Burlington, MA 01803-5005		WWW:   http://ajs.com/~ajs/
		ajs@ajs.com or ajs@openmarket.com
		      "I speak for no one."