From: John Napiorkowski Date: Wed, 6 Jul 2016 14:08:05 +0000 (-0500) Subject: example short circuit prepare phase X-Git-Tag: 5.90110~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=33b21eec9758f7416ced7908b2aa56b2573444c2;hp=5df9a4c5adf79f83fa4e54196c321f323c24670d example short circuit prepare phase --- diff --git a/t/unicode-exception-bug.t b/t/unicode-exception-bug.t new file mode 100644 index 0000000..cdcbd30 --- /dev/null +++ b/t/unicode-exception-bug.t @@ -0,0 +1,74 @@ +use strict; +use warnings; +use Test::More; + +BEGIN { + package TestApp::Exception; + $INC{'TestApp/Exception.pm'} = __FILE__; + + sub new { + my ($class, $code, $headers, $body) = @_; + return bless +{res => [$code, $headers, $body]}, $class; + } + + sub throw { die shift->new(@_) } + + sub as_psgi { + my ($self, $env) = @_; + my ($code, $headers, $body) = @{$self->{res}}; + + return [$code, $headers, $body]; # for now + + return sub { + my $responder = shift; + $responder->([$code, $headers, $body]); + }; + } + + package TestApp::Controller::Root; + $INC{'TestApp/Controller/Root.pm'} = __FILE__; + + use Moose; + use MooseX::MethodAttributes; + extends 'Catalyst::Controller'; + + sub main :Path('') :Args(1) { + my ($self, $c, $arg) = @_; + $c->res->body('

OK

'); + $c->res->content_type('text/html'); + } + + TestApp::Controller::Root->config(namespace => ''); +} + +{ + package TestApp; + $INC{'TestApp.pm'} = __FILE__; + + use Catalyst; + use TestApp::Exception; + + sub handle_unicode_encoding_exception { + my ( $self, $param_value, $error_msg ) = @_; + TestApp::Exception->throw( + 200, ['content-type'=>'text/plain'], ['Bad unicode data']); + } + + __PACKAGE__->setup; +} + + +use Catalyst::Test 'TestApp'; + +{ + my $res = request('/ok'); + is ($res->status_line, "200 OK"); + is ($res->content, '

OK

'); +} + +{ + my $res = request('/%E2%C3%83%C6%92%C3%8'); + is ($res->content, 'Bad unicode data'); +} + +done_testing;