Un-TODO abraxxa's tests
[catagits/Catalyst-Runtime.git] / t / aggregate / live_engine_request_escaped_path.t
CommitLineData
b4b58469 1#!/usr/bin/evn perl
7665bd7e 2use strict;
3use warnings;
4
5use FindBin;
6use lib "$FindBin::Bin/../lib";
7
8use Test::More tests => 6;
9use TestApp;
10use HTTP::Request::AsCGI;
11
12=pod
13
14This test exposes a problem in the handling of PATH_INFO in C::Engine::CGI (and
15other engines) where Catalyst does not un-escape the request correctly.
a0d17f88 16If a request is URL-encoded then Catalyst fails to decode the request
7665bd7e 17and thus will try and match actions using the URL-encoded value.
18
19Can NOT use Catalyst::Test as it uses HTTP::Request::AsCGI which does
20correctly unescape the path (by calling $uri = $uri->canonical).
21
22This will fix the problem for the CGI engine, but is probably the
23wrong place. And also does not fix $uri->base, either.
24
25Plus, the same issue is in Engine::Apache* and other engines.
26
27Index: lib/Catalyst/Engine/CGI.pm
28===================================================================
29--- lib/Catalyst/Engine/CGI.pm (revision 7821)
30+++ lib/Catalyst/Engine/CGI.pm (working copy)
31@@ -157,6 +157,8 @@
32 my $query = $ENV{QUERY_STRING} ? '?' . $ENV{QUERY_STRING} : '';
33 my $uri = $scheme . '://' . $host . '/' . $path . $query;
a0d17f88 34
7665bd7e 35+ $uri = URI->new( $uri )->canonical;
36+
37 $c->request->uri( bless \$uri, $uri_class );
a0d17f88 38
7665bd7e 39 # set the base URI
40
41=cut
42
43# test that un-escaped can be feteched.
44{
45
46 my $request = Catalyst::Utils::request( 'http://localhost/args/params/one/two' );
47 my $cgi = HTTP::Request::AsCGI->new( $request, %ENV )->setup;
48
9ec0ae77 49 TestApp->handle_request( env => \%ENV );
7665bd7e 50
51 ok( my $response = $cgi->restore->response );
52 ok( $response->is_success, 'Response Successful 2xx' );
53 is( $response->content, 'onetwo' );
54}
55
56# test that request with URL-escaped code works.
a0d17f88 57{
7665bd7e 58 my $request = Catalyst::Utils::request( 'http://localhost/args/param%73/one/two' );
59 my $cgi = HTTP::Request::AsCGI->new( $request, %ENV )->setup;
60
61 # Reset PATH_INFO because AsCGI calls $uri = $uri->canonical which
62 # will unencode the path and hide the problem from the test.
63 $ENV{PATH_INFO} = '/args/param%73/one/two';
64
65
9ec0ae77 66 TestApp->handle_request( env => \%ENV );
7665bd7e 67
68 ok( my $response = $cgi->restore->response );
69 ok( $response->is_success, 'Response Successful 2xx' );
70 is( $response->content, 'onetwo' );
71}
72