AsCGI - check that utf8 paths survive, unescape passed in PATH_INFO
[catagits/HTTP-Request-AsCGI.git] / t / 05env.t
CommitLineData
6f5fb9a7 1#!perl
2
b332ee65 3use Test::More tests => 10;
6f5fb9a7 4
5use strict;
6use warnings;
7
6f5fb9a7 8use HTTP::Request;
9use HTTP::Request::AsCGI;
8596f5a5 10use Encode;
6f5fb9a7 11
bb6e4a92 12my $r = HTTP::Request->new( GET => 'http://www.host.com/cgi-bin/script.cgi/my%20path%2F?a=1&b=2', [ 'X-Test' => 'Test' ] );
8596f5a5 13my %e = (
14 SCRIPT_NAME => '/cgi-bin/script.cgi',
15# test a utf-8 PATH_INFO, sort of (and safe decoding)
16 PATH_INFO =>
17 '/foo%2F%C3%90%C2%91%C3%90%C2%AF%C3%A9%C2%99%C2%B0%C3%A8%C2%8C%C2%8E',
18);
b332ee65 19my $c = HTTP::Request::AsCGI->new( $r, %e );
20$c->stdout(undef);
6f5fb9a7 21
22$c->setup;
23
24is( $ENV{GATEWAY_INTERFACE}, 'CGI/1.1', 'GATEWAY_INTERFACE' );
25is( $ENV{HTTP_HOST}, 'www.host.com:80', 'HTTP_HOST' );
30efa07d 26is( $ENV{HTTP_X_TEST}, 'Test', 'HTTP_X_TEST' );
8596f5a5 27is( decode('UTF-8', $ENV{PATH_INFO}), '/foo%2FБЯ陰茎', 'PATH_INFO');
6f5fb9a7 28is( $ENV{QUERY_STRING}, 'a=1&b=2', 'QUERY_STRING' );
ca38286c 29is( $ENV{SCRIPT_NAME}, '/cgi-bin/script.cgi', 'SCRIPT_NAME' );
6f5fb9a7 30is( $ENV{REQUEST_METHOD}, 'GET', 'REQUEST_METHOD' );
31is( $ENV{SERVER_NAME}, 'www.host.com', 'SERVER_NAME' );
32is( $ENV{SERVER_PORT}, '80', 'SERVER_PORT' );
33
34$c->restore;
35
36is( $ENV{GATEWAY_INTERFACE}, undef, 'No CGI env after restore' );