On Sunday, Jun 8, 2003, at 15:38 US/Pacific, steve ryan wrote: [..]
The problem is -

1. My "+" symbols are not being replaced (i.e. the spaces in the form)
2. My HEX/Ascii conversion isn't working (i.e. i am getting things like %2C)
[..]

steve,

First off, I do so try to avoid using "\n" and "\r" when
dealing with HTML stuff, since it is never a sure deal that
everyone will agree with what those mean - so I use the boring

our $CRLF = "\015\012"; # "\r\n" is not portable

after playing around, I think what you may have missed is the
fact that the 'string' that got handed back to you was already
urlencoded, and needed to be 'unpacked' first before you go
and deal with specific characters in it.

So help me out here, I think of the query string as a long bunch
of charcters say something like:

fancy+name=this%3Dlong+%26thing%3A+what+is+strange%3B&var=some+stuff+and %2C+other&hill=dick+%2B+jane&bob=frodo%40shire

which I want to unpack into 'useful' information - say a hash of stuff like:

        var => some stuff and, other
        fancy name => this=long &thing: what is strange;
        hill => dick + jane
        bob => [EMAIL PROTECTED]

As such your '$value' is the value side of the query string? once you
have unpacked the 'var=value' pairs out of the query string???? Or are
you trying to work against the whole of the QueryString itself?

Which was a mistake I made the first time out the shoot, and found it
best to break the query string up into it's constituent parts and
then decrypt it.

I ripped off, and then twiddled the following from someone:

#------------------------
# Our idea is to pass in a hash
# $ref->{key} = $val that would
# normally be formed as
# ?key=val
sub url_packer($)
{
        my ($ref) = @_;
        my $url;
        while ( my ($k, $v) = each %$ref)
        {
                $v ='' unless defined($v);
                $k =~ s/([^ \w])/"%" . uc(sprintf("%2.2x",ord($1)))/eg;
                $v =~ s/([^ \w])/"%" . uc(sprintf("%2.2x",ord($1)))/eg;
                $v =~ s/ /+/g;
                $k =~ s/ /+/g;  
                $url .= (defined($url))?
                                        "&$k=$v" : "$k=$v";
        }
        
        $url;

} # end of url_packer

#------------------------
#
sub unpack_query_string($)
{
        my ($qstring) = @_;
        
        return unless $qstring;
        
        my $queryHash;
        
        chomp($qstring);
        my @args = split(/&/, $qstring);
        
        foreach my $thing ( @args) {
                my ($k, $v) = split(/=/, $thing);
                next unless(defined($v) && $v ne '');
                # double coverage here, requires var=val structure
                $k =~ s/\+/ /g; $k =~ s/%(..)/pack("c",hex($1))/ge;
                $v =~ s/\+/ /g; $v =~ s/%(..)/pack("c",hex($1))/ge;
                $v =~ s/\s+$//;
                $v =~ s/^\s+//;
                $queryHash->{$k} = $v;
        }

$queryHash;

} # end of unpack_query_string


Purists will of course note that the unpack_query_string does not work and play well with 'multiple select' types of options - but I have another variant that deals with that....



ciao
drieux

---


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to