X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst.pm;h=1808a4dcf6e0df3330d53d27aa3da40afe16d7e7;hp=ecaeb949a9edbf23b65a8fb2314b1438b053020f;hb=de2e9a6f5290e2f0b0971ce995ae65afc1cacf0a;hpb=5df9a4c5adf79f83fa4e54196c321f323c24670d
diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm
index ecaeb94..1808a4d 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.90110';
$VERSION = eval $VERSION if $VERSION =~ /_/; # numify for warning-free dev releases
sub import {
@@ -2466,9 +2466,6 @@ sub prepare {
# VERY ugly and probably shouldn't rely on ->finalize actually working
catch {
# failed prepare is always due to an invalid request, right?
- $c->response->status(400);
- $c->response->content_type('text/plain');
- $c->response->body('Bad Request');
# Note we call finalize and then die here, which escapes
# finalize being called in the enclosing block..
# It in fact couldn't be called, as we don't return $c..
@@ -2476,8 +2473,20 @@ sub prepare {
# breaking compat for people doing crazy things (we should set
# the 400 and just return the ctx here IMO, letting finalize get called
# above...
- $c->finalize;
- die $_;
+ if ( $c->_handle_http_exception($_) ) {
+ foreach my $err (@{$c->error}) {
+ $c->log->error($err);
+ }
+ $c->clear_errors;
+ $c->log->_flush if $c->log->can('_flush');
+ $_->can('rethrow') ? $_->rethrow : croak $_;
+ } else {
+ $c->response->status(400);
+ $c->response->content_type('text/plain');
+ $c->response->body('Bad Request');
+ $c->finalize;
+ die $_;
+ }
};
$c->log_request;
@@ -3563,15 +3572,37 @@ sub setup_encoding {
=head2 handle_unicode_encoding_exception
Hook to let you customize how encoding errors are handled. By default
-we just throw an exception. Receives a hashref of debug information.
-Example:
+we just throw an exception and the default error page will pick it up.
+Receives a hashref of debug information. Example of call:
$c->handle_unicode_encoding_exception({
param_value => $value,
error_msg => $_,
- encoding_step => 'params',
+ encoding_step => 'params',
});
+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:
+
+ sub handle_unicode_encoding_exception {
+ my ($c, $params) = @_;
+ HTTP::Exception::BAD_REQUEST->throw(status_message=>$params->{error_msg});
+ }
+
+Alternatively you can 'catch' the error, stash it and write handling code later
+in your application:
+
+ sub handle_unicode_encoding_exception {
+ my ($c, $params) = @_;
+ $c->stash(BAD_UNICODE_DATA=>$params);
+ 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.
+
=cut
sub handle_unicode_encoding_exception {
@@ -3611,16 +3642,17 @@ sub _handle_unicode_decoding {
}
sub _handle_param_unicode_decoding {
- my ( $self, $value ) = @_;
+ my ( $self, $value, $check ) = @_;
return unless defined $value; # not in love with just ignoring undefs - jnap
return $value if blessed($value); #don't decode when the value is an object.
my $enc = $self->encoding;
+ $check ||= $self->_encode_check;
return try {
- $enc->decode( $value, $self->_encode_check );
+ $enc->decode( $value, $check);
}
catch {
- $self->handle_unicode_encoding_exception({
+ return $self->handle_unicode_encoding_exception({
param_value => $value,
error_msg => $_,
encoding_step => 'params',
@@ -4321,8 +4353,16 @@ evil clients, this might cause you trouble. If you find the changes introduced
in Catalyst version 5.90080+ break some of your query code, you may disable
the UTF-8 decoding globally using this configuration.
-This setting takes precedence over C and
-C
+This setting takes precedence over C
+
+=item *
+
+C
+
+Catalyst versions 5.90080 - 5.90106 would decode query parts of an incoming
+request but would not raise an exception when the decoding failed due to
+incorrect unicode. It now does, but if this change is giving you trouble
+you may disable it by setting this configuration to true.
=item *
@@ -4333,15 +4373,6 @@ is our reading of the relevant specifications. This setting allows one to
specify a fixed value for how to decode your query. You might need this if
you are doing a lot of custom encoding of your URLs and not using UTF-8.
-This setting take precedence over C.
-
-=item *
-
-C
-
-Setting this to true will default your query decoding to whatever your
-general global encoding is (the default is UTF-8).
-
=item *
C