X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst.pm;h=e68e18cb3f92738bfa7dd59c75052c9fcb8c332c;hp=f3e55251c0bfceb65769d8330f1541f690c4000a;hb=4dee90936d34763db2a273855abadc52cd65c379;hpb=ef52d28f14574311a08012a742a704c36fd1cc28 diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index f3e5525..e68e18c 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -204,7 +204,7 @@ sub composed_stats_class { __PACKAGE__->_encode_check(Encode::FB_CROAK | Encode::LEAVE_SRC); # Remember to update this in Catalyst::Runtime as well! -our $VERSION = '5.90106'; +our $VERSION = '5.90112'; $VERSION = eval $VERSION if $VERSION =~ /_/; # numify for warning-free dev releases sub import { @@ -3571,18 +3571,23 @@ sub setup_encoding { =head2 handle_unicode_encoding_exception -Hook to let you customize how encoding errors are handled. By default +Hook to let you customize how encoding errors are handled. By default we just throw an exception and the default error page will pick it up. -Receives a hashref of debug information. Example of call: +Receives a hashref of debug information. Example of call (from the +Catalyst internals): - $c->handle_unicode_encoding_exception({ + my $decoded_after_fail = $c->handle_unicode_encoding_exception({ param_value => $value, error_msg => $_, encoding_step => 'params', - }); + }); + +The calling code expects to receive a decoded string or an exception. -You can override this for custom handling of unicode errors. If you want a -custom response here, one approach is to throw an HTTP style exception: +You can override this for custom handling of unicode errors. By +default we just die. If you want a custom response here, one approach +is to throw an HTTP style exception, instead of returning a decoded +string or throwing a generic exception. sub handle_unicode_encoding_exception { my ($c, $params) = @_; @@ -3595,13 +3600,15 @@ in your application: sub handle_unicode_encoding_exception { my ($c, $params) = @_; $c->stash(BAD_UNICODE_DATA=>$params); + # return a dummy string. return 1; } -NOTE: Please keep in mind that once an error like this occurs, the request -setup is aborted, which means the state of C<$c> and related context parts like -the request and response may not be setup up correctly (since we never finished the -setup. +NOTE: Please keep in mind that once an error like this occurs, +the request setup is still ongoing, which means the state of C<$c> and +related context parts like the request and response may not be setup +up correctly (since we haven't finished the setup yet). If you throw +an exception the setup is aborted. =cut @@ -3647,6 +3654,9 @@ sub _handle_param_unicode_decoding { return $value if blessed($value); #don't decode when the value is an object. my $enc = $self->encoding; + + return $value unless $enc; # don't decode if no encoding is specified + $check ||= $self->_encode_check; return try { $enc->decode( $value, $check);