# This file documents the revision history for Perl extension Catalyst.
+5.90076 - 2014-11-13
+ - If throwing an exception object that does the code method, make sure that
+ method returns an expected HTTP status code before passing it on to the
+ HTTP Exception middleware.
+
5.90075 - 2014-10-06
- Documentation patch for $c->req->param to point out the recently discovered
potential security issues: http://blog.gerv.net/2014/10/new-class-of-vulnerability-in-perl-web-applications/
__PACKAGE__->_encode_check(Encode::FB_CROAK | Encode::LEAVE_SRC);
# Remember to update this in Catalyst::Runtime as well!
-our $VERSION = '5.90075';
+our $VERSION = '5.90076';
sub import {
my ( $class, @arguments ) = @_;
if ( my $error = $@ ) {
#rethow if this can be handled by middleware
- if(blessed $error && ($error->can('as_psgi') || $error->can('code'))) {
+ if(
+ blessed $error && (
+ $error->can('as_psgi') ||
+ (
+ $error->can('code') &&
+ $error->code =~m/^[1-5][0-9][0-9]$/
+ )
+ )
+ ) {
foreach my $err (@{$c->error}) {
$c->log->error($err);
}
$status = $c->finalize;
} catch {
#rethow if this can be handled by middleware
- if(blessed $_ && ($_->can('as_psgi') || $_->can('code'))) {
+ if(
+ blessed($_) && (
+ $_->can('as_psgi') ||
+ (
+ $_->can('code') &&
+ $_->code =~m/^[1-5][0-9][0-9]$/
+ )
+ )
+ ) {
$_->can('rethrow') ? $_->rethrow : croak $_;
}
chomp(my $error = $_);
# Remember to update this in Catalyst as well!
-our $VERSION = '5.90075';
+our $VERSION = '5.90076';
=head1 NAME
{
package MyApp::Exception;
- use overload
- # Use the overloading thet HTTP::Exception uses
- bool => sub { 1 }, '""' => 'as_string', fallback => 1;
-
sub new {
my ($class, $code, $headers, $body) = @_;
return bless +{res => [$code, $headers, $body]}, $class;
};
}
+ package MyApp::AnotherException;
+
+ sub new { bless +{}, shift }
+
+ sub code { 400 }
+
sub as_string { 'bad stringy bad' }
-
+
package MyApp::Controller::Root;
use base 'Catalyst::Controller';
403, ['content-type'=>'text/plain'], ['Forbidden']);
}
+ sub from_code_type :Local {
+ my $e = MyApp::AnotherException->new;
+ die $e;
+ }
+
sub classic_error :Local {
my ($self, $c) = @_;
Catalyst::Exception->throw("Ex Parrot");
test_psgi $psgi, sub {
my $cb = shift;
+ my $res = $cb->(GET "/root/from_code_type");
+ is $res->code, 400;
+ is $res->content, 'bad stringy bad', 'bad stringy bad';
+ unlike $res->content, qr'HTTPExceptions', 'HTTPExceptions';
+};
+
+test_psgi $psgi, sub {
+ my $cb = shift;
my $res = $cb->(GET "/root/classic_error");
is $res->code, 500;
like $res->content, qr'Ex Parrot', 'Ex Parrot';
# in the callbacks might never get run (thus all ran tests pass but not all
# required tests run).
-done_testing(14);
+done_testing(17);
--- /dev/null
+use utf8;
+use warnings;
+use strict;
+
+use Test::More;
+use HTTP::Request::Common;
+use Plack::Test;
+
+# Test cases for incoming utf8
+
+{
+ package MyApp::Controller::Root;
+ $INC{'MyApp/Controller/Root.pm'} = __FILE__;
+
+ use base 'Catalyst::Controller';
+
+ sub heart :Path('♥') {
+ my ($self, $c) = @_;
+ $c->response->body("This is the body");
+ }
+
+ sub hat :Path('^') {
+ my ($self, $c) = @_;
+ $c->response->body("This is the body");
+ }
+
+ sub base :Chained('/') CaptureArgs(0) { }
+ sub link :Chained('base') PathPart('♥') Args(0) {
+ my ($self, $c) = @_;
+ $c->response->body("This is the body");
+ }
+
+ package MyApp;
+ use Catalyst;
+
+ Test::More::ok(MyApp->setup, 'setup app');
+}
+
+ok my $psgi = MyApp->psgi_app, 'build psgi app';
+
+test_psgi $psgi, sub {
+ my $cb = shift;
+ #my $res = $cb->(GET "/root/test");
+ #is $res->code, 200, 'OK';
+ #is $res->content, 'This is the body', 'correct body';
+ #is $res->content_length, 16, 'correct length';
+};
+
+done_testing;