6 use lib "$FindBin::Bin/../lib";
8 use Test::More tests => 6;
10 use HTTP::Request::AsCGI;
14 This test exposes a problem in the handling of PATH_INFO in C::Engine::CGI (and
15 other engines) where Catalyst does not un-escape the request correctly.
16 If a request is URL-encoded then Catalyst fails to decode the request
17 and thus will try and match actions using the URL-encoded value.
19 Can NOT use Catalyst::Test as it uses HTTP::Request::AsCGI which does
20 correctly unescape the path (by calling $uri = $uri->canonical).
22 This will fix the problem for the CGI engine, but is probably the
23 wrong place. And also does not fix $uri->base, either.
25 Plus, the same issue is in Engine::Apache* and other engines.
27 Index: lib/Catalyst/Engine/CGI.pm
28 ===================================================================
29 --- lib/Catalyst/Engine/CGI.pm (revision 7821)
30 +++ lib/Catalyst/Engine/CGI.pm (working copy)
32 my $query = $ENV{QUERY_STRING} ? '?' . $ENV{QUERY_STRING} : '';
33 my $uri = $scheme . '://' . $host . '/' . $path . $query;
35 + $uri = URI->new( $uri )->canonical;
37 $c->request->uri( bless \$uri, $uri_class );
43 # test that un-escaped can be feteched.
46 my $request = Catalyst::Utils::request( 'http://localhost/args/params/one/two' );
47 my $cgi = HTTP::Request::AsCGI->new( $request, %ENV )->setup;
49 TestApp->handle_request( env => \%ENV );
51 ok( my $response = $cgi->restore->response );
52 ok( $response->is_success, 'Response Successful 2xx' );
53 is( $response->content, 'onetwo' );
56 # test that request with URL-escaped code works.
58 local $TODO = 'Actions should match when path parts are url encoded';
59 my $request = Catalyst::Utils::request( 'http://localhost/args/param%73/one/two' );
60 my $cgi = HTTP::Request::AsCGI->new( $request, %ENV )->setup;
62 # Reset PATH_INFO because AsCGI calls $uri = $uri->canonical which
63 # will unencode the path and hide the problem from the test.
64 $ENV{PATH_INFO} = '/args/param%73/one/two';
67 TestApp->handle_request( env => \%ENV );
69 ok( my $response = $cgi->restore->response );
70 ok( $response->is_success, 'Response Successful 2xx' );
71 is( $response->content, 'onetwo' );