Changeset 44

Show
Ignore:
Timestamp:
03/25/09 15:31:13 (5 years ago)
Author:
clinton
Message:

Fix to allow multi-valued query-string parameters

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/Mungo/Request.pm

    r43 r44  
    147147sub QueryString { 
    148148  my $self = shift; 
    149   my (@params) = $self->{'Mungo'}->{'Apache::Request'}->args; 
    150   my %qs; 
    151   if(@params == 1) { 
    152     # in mod_perl2 ->args is just a string 
    153     %qs = map { s/\+/ /g; s/%([0-9a-f]{2})/chr(hex($1))/ige; $_ } 
    154               (map { (split /=/, $_, 2) } (split /&/, $params[0])); 
    155   } 
    156   else { 
    157     # mod_perl1 splits it up for us 
    158     %qs = @params; 
    159   } 
    160   return exists($qs{$_[0]})?$qs{$_[0]}:undef if(@_); 
    161   return %qs if wantarray; 
    162   return \%qs; 
     149  my $qs_string = $self->{'Mungo'}->{'Apache::Request'}->args; 
     150 
     151  my %params; 
     152  foreach my $kv_pair (split /&/, $qs_string) { 
     153      my ($k, $v) = split(/=/, $kv_pair, 2); 
     154 
     155      # $v = uri_unescape($v); # If CPAN dep on URI::Escape were allowed 
     156      $v =~ s/%([0-9a-f]{2})/chr(hex($1))/ige; 
     157      $v =~ s/\+/ /g; 
     158 
     159      if (exists($params{$k}) && ref($params{$k})) { 
     160          push @{$params{$k}}, $v; 
     161      } elsif (exists($params{$k})) { 
     162          $params{$k} = [ $params{$k}, $v]; 
     163      } else { 
     164          $params{$k} = $v; 
     165      } 
     166  } 
     167  if (@_) { 
     168      return exists($params{$_[0]}) ? $params{$_[0]} : undef; 
     169  } 
     170  return %params if wantarray; 
     171  return \%params; 
    163172} 
    164173