X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FEngine.pm;h=70f49fb488d8f1162c5ae48c56bf27658a14df55;hp=5e87e9f62604d9171956171ec853360adf7761b5;hb=199731fb710c6a165793f055f85de60539039dfe;hpb=9c056c82094f7550ac9e39408c52d248bcace7b3 diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index 5e87e9f..70f49fb 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -574,38 +574,48 @@ sub prepare_query_parameters { my ($self, $c) = @_; my $env = $c->request->env; my $do_not_decode_query = $c->config->{do_not_decode_query}; - my $default_query_encoding = $c->config->{default_query_encoding} || - ($c->config->{decode_query_using_global_encoding} ? - $c->encoding : 'UTF-8'); + my $old_encoding; + if(my $new = $c->config->{default_query_encoding}) { + $old_encoding = $c->encoding; + $c->encoding($new); + } + + my $check = $c->config->{do_not_check_query_encoding} ? undef :$c->_encode_check; my $decoder = sub { my $str = shift; return $str if $do_not_decode_query; - return $str unless $default_query_encoding; - return decode( $default_query_encoding, $str); + return $c->_handle_param_unicode_decoding($str, $check); }; my $query_string = exists $env->{QUERY_STRING} ? $env->{QUERY_STRING} : ''; - # Check for keywords (no = signs) - # (yes, index() is faster than a regex :)) - if ( index( $query_string, '=' ) < 0 ) { - my $keywords = $self->unescape_uri($query_string); - $keywords = $decoder->($keywords); - $c->request->query_keywords($keywords); - return; - } - $query_string =~ s/\A[&;]+//; - my $p = Hash::MultiValue->new( - map { defined $_ ? $decoder->($self->unescape_uri($_)) : $_ } - map { ( split /=/, $_, 2 )[0,1] } # slice forces two elements - split /[&;]+/, $query_string - ); + my @unsplit_pairs = split /[&;]+/, $query_string; + my $p = Hash::MultiValue->new(); + my $is_first_pair = 1; + for my $pair (@unsplit_pairs) { + my ($name, $value) + = map { defined $_ ? $decoder->($self->unescape_uri($_)) : $_ } + ( split /=/, $pair, 2 )[0,1]; # slice forces two elements + + if ($is_first_pair) { + # If the first pair has no equal sign, then it means the isindex + # flag is set. + $c->request->query_keywords($name) unless defined $value; + + $is_first_pair = 0; + } + + $p->add( $name => $value ); + } + + + $c->encoding($old_encoding) if $old_encoding; $c->request->query_parameters( $c->request->_use_hash_multivalue ? $p : $p->mixed ); } @@ -650,8 +660,8 @@ sub prepare_uploads { my $uploads = $request->_body->upload; my $parameters = $request->parameters; foreach my $name (keys %$uploads) { - $name = $c->_handle_unicode_decoding($name) if $enc; my $files = $uploads->{$name}; + $name = $c->_handle_unicode_decoding($name) if $enc; my @uploads; for my $upload (ref $files eq 'ARRAY' ? @$files : ($files)) { my $headers = HTTP::Headers->new( %{ $upload->{headers} } );