Hello!

Does anyone use these plugins together?

Catalyst::Plugin::Unicode::Encoding doesn't decode parameter when it is 
prepared by Catalyst::Plugin::Params::Nested (sub prepare_parameters)

I've made a simple patch for Catalyst::Plugin::Unicode::Encoding, so I think 
it should work properly.

PS: sorry for my English

-- 
//wbr, Dmitry L.
*** Encoding.pm	2011-02-28 14:36:59.000000000 +0300
--- /tmp/patched/Encoding.pm	2011-02-28 15:00:30.000000000 +0300
***************
*** 72,77 ****
--- 72,111 ----
      $c->next::method(@_);
  }
  
+ sub _decode_param
+ {
+ 	my $c = shift;
+ 	my $param = shift;
+ 
+ 	my $enc = $c->encoding;
+ 
+ 	# N.B. Check if already a character string and if so do not try to double decode.
+ 	#      http://www.mail-archive.com/catalyst@lists.scsys.co.uk/msg02350.html
+ 	#      this avoids exception if we have already decoded content, and is _not_ the
+ 	#      same as not encoding on output which is bad news (as it does the wrong thing
+ 	#      for latin1 chars for example)..
+ 	return (Encode::is_utf8( $param ) ? $param : $enc->decode( $param, $CHECK ));
+ }
+ 
+ sub _prepare_hashed_parameters
+ {
+ 	my $c = shift;
+ 	my $value = shift;
+ 
+ 	foreach my $key (keys(%{$value}))
+ 	{
+ 		if ( ref $value->{$key} && ref $value->{$key} ne 'ARRAY' )
+ 		{
+ 			$c->_prepare_hashed_parameters($value->{$key});
+ 			next;
+ 		}
+ 		for ( ref($value->{$key}) ? @{$value->{$key}} : $value->{$key} )
+ 		{
+ 			$_ = $c->_decode_param($_);
+ 		}
+ 	}
+ }
+ 
  # Note we have to hook here as uploads also add to the request parameters
  sub prepare_uploads {
      my $c = shift;
***************
*** 83,99 ****
      for my $key (qw/ parameters query_parameters body_parameters /) {
          for my $value ( values %{ $c->request->{$key} } ) {
  
!             # TODO: Hash support from the Params::Nested
              if ( ref $value && ref $value ne 'ARRAY' ) {
                  next;
              }
              for ( ref($value) ? @{$value} : $value ) {
!                 # N.B. Check if already a character string and if so do not try to double decode.
!                 #      http://www.mail-archive.com/catalyst@lists.scsys.co.uk/msg02350.html
!                 #      this avoids exception if we have already decoded content, and is _not_ the
!                 #      same as not encoding on output which is bad news (as it does the wrong thing
!                 #      for latin1 chars for example)..
!                 $_ = Encode::is_utf8( $_ ) ? $_ : $enc->decode( $_, $CHECK );
              }
          }
      }
--- 117,129 ----
      for my $key (qw/ parameters query_parameters body_parameters /) {
          for my $value ( values %{ $c->request->{$key} } ) {
  
!             # Hash support from the Params::Nested
              if ( ref $value && ref $value ne 'ARRAY' ) {
+                 $c->_prepare_hashed_parameters($value);
                  next;
              }
              for ( ref($value) ? @{$value} : $value ) {
!                 $_ = $c->_decode_param($_);
              }
          }
      }
_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/

Reply via email to