Several months ago i was playing with pulling form vars from URI's. The problem is handling multiple keys such as 'foo=bar&foo=baz'. I decided to use URI and was shocked to find that the following code:
use URI; use Data::Dumper; my $uri = URI->new('http://localhost/foo.cgi?foo=bar&foo=baz'); my %form_var = $uri->query_form; print Dumper \%form_var;
Yielded:

$VAR1 = {
          'foo' => 'baz'
        };
So i hunted down query_form() (it is located in URI/_query.pm) and discovered this at the end of that subroutine:
map { s/\+/ /g; uri_unescape($_) } map { /=/ ? split(/=/, $_, 2) : ($_ => '')} split(/&/, $old);
Then i decided to recode that with something like this:
my %hash; for my $pair (split /&/, $old) { my ($k,$v) = map { s/\+/ /g; uri_unescape($_) } split /=/, $pair, 2; if (exists $hash{$k}) { if (ref $hash{$k}) { push @{$hash{$k}}, $v; } else { $hash{$k} = [$hash{$k},$v]; } } else { $hash{$k} = $v; } } return %hash;
Now when i run my test code, i get the output i expect:

$VAR1 = {
          'foo' => [
                     'bar',
                     'baz'
                   ]
        };
The reason i am bringing this up is because i submitted this as a patch to Gisle Aas and never heard back. The bug has been 'resolved', but my test case is contrary ...

Is this really a 'bug' in URI or am i missing something? I really feel that query_form() should handle multiple values with the same key, but giving the lack of response i got from Mr. Aas, i can't help but think i am missing something ... thanks :) (oh, and i am not ruling out the possibility that my message never reached Mr. Aas. - i just want to be sure before i bug him again.)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to URI.pm bug or am i missing something? by jeffa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.