query not checks unicode like post and args
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine.pm
index e4deb9e..150c269 100644 (file)
@@ -159,11 +159,11 @@ sub finalize_body {
           }
           else {
               
-              # Case where body was set afgter calling ->write.  We'd prefer not to
+              # Case where body was set after calling ->write.  We'd prefer not to
               # support this, but I can see some use cases with the way most of the
-              # views work.
-
-              $self->write($c, $body );
+              # views work. Since body has already been encoded, we need to do
+              # an 'unencoded_write' here.
+              $self->unencoded_write( $c, $body );
           }
         }
 
@@ -574,15 +574,18 @@ 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}
@@ -606,6 +609,7 @@ sub prepare_query_parameters {
         split /[&;]+/, $query_string
     );
 
+    $c->encoding($old_encoding) if $old_encoding;
     $c->request->query_parameters( $c->request->_use_hash_multivalue ? $p : $p->mixed );
 }
 
@@ -650,8 +654,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} } );
@@ -700,6 +704,20 @@ sub write {
     $c->response->write($buffer);
 }
 
+=head2 $self->unencoded_write($c, $buffer)
+
+Writes the buffer to the client without encoding. Necessary for
+already encoded buffers. Used when a $c->write has been done
+followed by $c->res->body.
+
+=cut
+
+sub unencoded_write {
+    my ( $self, $c, $buffer ) = @_;
+
+    $c->response->unencoded_write($buffer);
+}
+
 =head2 $self->read($c, [$maxlength])
 
 Reads from the input stream by calling C<< $self->read_chunk >>.