10 use Catalyst::Test 'TestAppUnicode';
12 use HTTP::Request::Common;
13 use URI::Escape qw/uri_escape_utf8/;
14 use HTTP::Status 'is_server_error';
16 my $encode_str = "\x{e3}\x{81}\x{82}"; # e38182 is japanese 'あ'
17 my $decode_str = Encode::decode('utf-8' => $encode_str);
18 my $escape_str = uri_escape_utf8($decode_str);
21 my ( undef, $c ) = ctx_request(shift);
22 is $c->res->output => '<h1>It works</h1>';
24 my $foo = $c->req->param('foo');
27 my $other_foo = $c->req->method eq 'POST'
28 ? $c->req->upload('foo')
29 ? $c->req->upload('foo')->filename
30 : $c->req->body_parameters->{foo}
31 : $c->req->query_parameters->{foo};
33 is $other_foo => $decode_str;
37 my ( undef, $c ) = ctx_request(shift);
38 is $c->res->output => '<h1>It works</h1>';
40 my $foo = $c->req->args->[0];
41 is $foo => $decode_str;
45 my ( undef, $c ) = ctx_request(shift);
46 is $c->res->output => '<h1>It works</h1>';
48 my $foo = $c->req->captures->[0];
49 is $foo => $decode_str;
53 my ( $res, $c ) = ctx_request(shift);
54 ok(!is_server_error($res->code)) or diag('Response code is: ' . $res->code);
57 check_parameter(GET "/?foo=$escape_str");
58 check_parameter(POST '/', ['foo' => $encode_str]);
59 check_parameter(POST '/',
60 Content_Type => 'form-data',
63 "$Bin/unicode_plugin_request_decode.t",
69 check_argument(GET "/$escape_str");
70 check_capture(GET "/capture/$escape_str");
72 # sending non-utf8 data
73 my $non_utf8_data = "%C3%E6%CB%AA";
74 check_fallback(GET "/?q=${non_utf8_data}");
75 check_fallback(GET "/${non_utf8_data}");
76 check_fallback(GET "/capture/${non_utf8_data}");
77 check_fallback(POST '/', ['foo' => $non_utf8_data]);