File: unicode_plugin_no_encoding.t

package info (click to toggle)
libcatalyst-perl 5.90075-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,712 kB
  • ctags: 1,428
  • sloc: perl: 12,388; makefile: 7
file content (46 lines) | stat: -rw-r--r-- 1,106 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use strict;
use warnings;
use Test::More;
use utf8;

# setup library path
use FindBin qw($Bin);
use lib "$Bin/lib";

use Catalyst::Test 'TestAppWithoutUnicode';
use Encode;
use HTTP::Request::Common;
use URI::Escape qw/uri_escape_utf8/;
use HTTP::Status 'is_server_error';
use Data::Dumper;

my $encode_str = "\x{e3}\x{81}\x{82}"; # e38182 is japanese 'あ'
my $decode_str = Encode::decode('utf-8' => $encode_str);
my $escape_str = uri_escape_utf8($decode_str);

check_parameter(GET "/?myparam=$escape_str");
check_parameter(POST '/',
    Content_Type => 'form-data',
    Content => [
        'myparam' => [
            "$Bin/unicode_plugin_no_encoding.t",
            "$Bin/unicode_plugin_request_decode.t",
        ]
    ],
);

sub check_parameter {
    my ( undef, $c ) = ctx_request(shift);

    my $myparam = $c->req->param('myparam');
    ok !utf8::is_utf8($myparam);
    unless ( $c->request->method eq 'POST' ) {
        is $c->res->output => $encode_str;
        is $myparam => $encode_str;
    }

    is scalar(@TestLogger::ELOGS), 0
        or diag Dumper(\@TestLogger::ELOGS);
}

done_testing;