| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mason::Plugin::WithEncoding::t::NoUTF8; |
|
2
|
|
|
|
|
|
|
$Mason::Plugin::WithEncoding::t::NoUTF8::VERSION = '0.2'; |
|
3
|
1
|
|
|
1
|
|
1551
|
use utf8; |
|
|
1
|
|
|
|
|
12
|
|
|
|
1
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
1366
|
use Test::Class::Most parent => 'Mason::Plugin::WithEncoding::Test::Class'; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Guard; |
|
7
|
|
|
|
|
|
|
use Poet::Tools qw(dirname mkpath trim write_file); |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# Setup stolen from Poet::t::Run and Poet::t::PSGIHandler |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub test_no_withencoding : Tests { |
|
12
|
|
|
|
|
|
|
my $self = shift; |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $conf_no_encoding = { |
|
15
|
|
|
|
|
|
|
'layer' => 'production', |
|
16
|
|
|
|
|
|
|
'server.port' => 9998, |
|
17
|
|
|
|
|
|
|
}; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $poet = $self->temp_env(conf => $conf_no_encoding); |
|
20
|
|
|
|
|
|
|
my $root_dir = $poet->root_dir; |
|
21
|
|
|
|
|
|
|
my $run_log = "$root_dir/logs/run.log"; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
if ( my $pid = fork() ) { |
|
24
|
|
|
|
|
|
|
# parent |
|
25
|
|
|
|
|
|
|
scope_guard { kill( 1, $pid ) }; |
|
26
|
|
|
|
|
|
|
sleep(2); |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $mech = $self->mech($poet); |
|
29
|
|
|
|
|
|
|
$self->add_comps($poet); |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# std config, utf8 content, utf8 url, utf8 query |
|
32
|
|
|
|
|
|
|
$mech->get_ok("http://127.0.0.1:9998/♥♥♥?♥♥=♥♥♥♥♥♥♥"); |
|
33
|
|
|
|
|
|
|
# query string goes over wires as encoded ascii, so clients use url encoding to preserve information |
|
34
|
|
|
|
|
|
|
$mech->content_unlike(qr/QUERY STRING FROM REQ: ♥♥=♥♥♥♥♥♥/); |
|
35
|
|
|
|
|
|
|
$mech->content_like(qr[QUERY STRING FROM REQ: \Q%E2%99%A5%E2%99%A5=%E2%99%A5%E2%99%A5%E2%99%A5%E2%99%A5%E2%99%A5%E2%99%A5%E2%99%A5\E]); |
|
36
|
|
|
|
|
|
|
$mech->content_unlike(qr/QUERY STRING UNESCAPED: ♥♥=♥♥♥♥♥♥♥/); |
|
37
|
|
|
|
|
|
|
#warn $mech->content; |
|
38
|
|
|
|
|
|
|
$mech->content_like(qr/A QUICK BROWN FOX JUMPS OVER THE LAZY DOG/); |
|
39
|
|
|
|
|
|
|
$mech->content_unlike(qr/a quick brown fox jumps over the lazy dog/); |
|
40
|
|
|
|
|
|
|
$mech->content_unlike(qr/ΔΙΑΦΥΛΆΞΤΕ ΓΕΝΙΚΆ ΤΗ ΖΩΉ ΣΑΣ ΑΠΌ ΒΑΘΕΙΆ ΨΥΧΙΚΆ ΤΡΑΎΜΑΤΑ/); #### WithEncode matches (uc operation works) |
|
41
|
|
|
|
|
|
|
$mech->content_like(qr/διαφυλάξτε γενικά τη ζωή σας από βαθειά ψυχικά τραύματα/); #### WithEncode doesn't match (uc operation works) |
|
42
|
|
|
|
|
|
|
is($mech->content_type, 'text/html', 'Got correct content type'); |
|
43
|
|
|
|
|
|
|
is($mech->response->content_type_charset, undef, 'Got correct content-type charset'); |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# std config, utf8 content, utf8 url, no query |
|
46
|
|
|
|
|
|
|
$mech->get_ok("http://127.0.0.1:9998/♥♥♥"); |
|
47
|
|
|
|
|
|
|
$mech->content_like(qr/A QUICK BROWN FOX JUMPS OVER THE LAZY DOG/); |
|
48
|
|
|
|
|
|
|
$mech->content_unlike(qr/a quick brown fox jumps over the lazy dog/); |
|
49
|
|
|
|
|
|
|
$mech->content_unlike(qr/ΔΙΑΦΥΛΆΞΤΕ ΓΕΝΙΚΆ ΤΗ ΖΩΉ ΣΑΣ ΑΠΌ ΒΑΘΕΙΆ ΨΥΧΙΚΆ ΤΡΑΎΜΑΤΑ/); #### WithEncode matches (uc operation works) |
|
50
|
|
|
|
|
|
|
$mech->content_like(qr/διαφυλάξτε γενικά τη ζωή σας από βαθειά ψυχικά τραύματα/); #### WithEncode doesn't match (uc operation works) |
|
51
|
|
|
|
|
|
|
is($mech->content_type, 'text/html', 'Got correct content type'); |
|
52
|
|
|
|
|
|
|
is($mech->response->content_type_charset, undef, 'Got correct content-type charset'); |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# std config, utf8 content, ascii url, utf8 query |
|
55
|
|
|
|
|
|
|
$mech->get_ok("http://127.0.0.1:9998/utf8?♥♥=♥♥♥♥♥♥♥"); |
|
56
|
|
|
|
|
|
|
# query string goes over wires as encoded ascii, so clients use url encoding to preserve information |
|
57
|
|
|
|
|
|
|
$mech->content_unlike(qr/QUERY STRING FROM REQ: ♥♥=♥♥♥♥♥♥/); |
|
58
|
|
|
|
|
|
|
$mech->content_like(qr[QUERY STRING FROM REQ: \Q%E2%99%A5%E2%99%A5=%E2%99%A5%E2%99%A5%E2%99%A5%E2%99%A5%E2%99%A5%E2%99%A5%E2%99%A5\E]); |
|
59
|
|
|
|
|
|
|
$mech->content_unlike(qr/QUERY STRING UNESCAPED: ♥♥=♥♥♥♥♥♥♥/); |
|
60
|
|
|
|
|
|
|
#warn $mech->content; |
|
61
|
|
|
|
|
|
|
$mech->content_like(qr/A QUICK BROWN FOX JUMPS OVER THE LAZY DOG/); |
|
62
|
|
|
|
|
|
|
$mech->content_unlike(qr/a quick brown fox jumps over the lazy dog/); |
|
63
|
|
|
|
|
|
|
$mech->content_unlike(qr/ΔΙΑΦΥΛΆΞΤΕ ΓΕΝΙΚΆ ΤΗ ΖΩΉ ΣΑΣ ΑΠΌ ΒΑΘΕΙΆ ΨΥΧΙΚΆ ΤΡΑΎΜΑΤΑ/); #### WithEncode matches (uc operation works) |
|
64
|
|
|
|
|
|
|
$mech->content_like(qr/διαφυλάξτε γενικά τη ζωή σας από βαθειά ψυχικά τραύματα/); #### WithEncode doesn't match (uc operation works) |
|
65
|
|
|
|
|
|
|
is($mech->content_type, 'text/html', 'Got correct content type'); |
|
66
|
|
|
|
|
|
|
is($mech->response->content_type_charset, undef, 'Got correct content-type charset'); |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# std config, utf8 content, ascii url, no query |
|
69
|
|
|
|
|
|
|
$mech->get_ok("http://127.0.0.1:9998/utf8"); |
|
70
|
|
|
|
|
|
|
#warn $mech->content; |
|
71
|
|
|
|
|
|
|
$mech->content_like(qr/A QUICK BROWN FOX JUMPS OVER THE LAZY DOG/); |
|
72
|
|
|
|
|
|
|
$mech->content_unlike(qr/a quick brown fox jumps over the lazy dog/); |
|
73
|
|
|
|
|
|
|
$mech->content_unlike(qr/ΔΙΑΦΥΛΆΞΤΕ ΓΕΝΙΚΆ ΤΗ ΖΩΉ ΣΑΣ ΑΠΌ ΒΑΘΕΙΆ ΨΥΧΙΚΆ ΤΡΑΎΜΑΤΑ/); #### WithEncode matches (uc operation works) |
|
74
|
|
|
|
|
|
|
$mech->content_like(qr/διαφυλάξτε γενικά τη ζωή σας από βαθειά ψυχικά τραύματα/); #### WithEncode doesn't match (uc operation works) |
|
75
|
|
|
|
|
|
|
is($mech->content_type, 'text/html', 'Got correct content type'); |
|
76
|
|
|
|
|
|
|
is($mech->response->content_type_charset, undef, 'Got correct content-type charset'); |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# std config, plain content, plain url, no query |
|
79
|
|
|
|
|
|
|
$mech->get_ok("http://127.0.0.1:9998/plain"); |
|
80
|
|
|
|
|
|
|
$mech->content_like(qr/LOREM IPSUM DOLOR SIT AMET/); |
|
81
|
|
|
|
|
|
|
$mech->content_unlike(qr/Lorem ipsum dolor sit amet/); |
|
82
|
|
|
|
|
|
|
#warn $mech->content; |
|
83
|
|
|
|
|
|
|
is($mech->content_type, 'text/html', 'Got correct content type'); |
|
84
|
|
|
|
|
|
|
is($mech->response->content_type_charset, undef, 'Got correct content-type charset'); |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# std config, chokes on $.args->{♥} in the page, looks like a bug |
|
87
|
|
|
|
|
|
|
$mech->get("http://127.0.0.1:9998/dies"); # PSGI error: Unrecognized character |
|
88
|
|
|
|
|
|
|
ok($mech->status == 500, 'UTF8 content bug'); |
|
89
|
|
|
|
|
|
|
#$mech->content_like(qr/♥♥♥♥♥♥♥/); |
|
90
|
|
|
|
|
|
|
is($mech->content_type, '', 'Got correct content type'); |
|
91
|
|
|
|
|
|
|
is($mech->response->content_type_charset, undef, 'Got correct content-type charset'); |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# std config, json content |
|
94
|
|
|
|
|
|
|
my $expected_from_json = { |
|
95
|
|
|
|
|
|
|
foo => 'bar', |
|
96
|
|
|
|
|
|
|
baz => [qw(barp beep)], |
|
97
|
|
|
|
|
|
|
9 => { one => 1, ex => 'EKS' }, |
|
98
|
|
|
|
|
|
|
heart => '♥', |
|
99
|
|
|
|
|
|
|
}; |
|
100
|
|
|
|
|
|
|
$mech->get_ok("http://127.0.0.1:9999/json"); |
|
101
|
|
|
|
|
|
|
#warn $mech->content; |
|
102
|
|
|
|
|
|
|
# see comments in UTF8.pm for why I can't use cmp_deeply |
|
103
|
|
|
|
|
|
|
#cmp_deeply(JSON->new->utf8->decode($mech->content), $expected_from_json, 'Decoded expected data from JSON'); # fails '�' - that's what is in the content |
|
104
|
|
|
|
|
|
|
#cmp_deeply(JSON->new->decode($mech->content), $expected_from_json, 'Decoded expected data from JSON'); # fails '�' |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
my $from_decoded_utf8 = JSON->new->utf8->decode($mech->content); # should work DOESN'T |
|
107
|
|
|
|
|
|
|
my $not_decoded = JSON->new->decode($mech->content); # should break |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
use Encode qw(); |
|
110
|
|
|
|
|
|
|
my $manually_decoded = JSON->new->decode(Encode::decode('UTF8', $mech->content)); # should work DOESN'T |
|
111
|
|
|
|
|
|
|
my $manually_and_JSON_decoded = JSON->new->utf8->decode(Encode::decode('UTF8', $mech->content)); # should break ISN'T |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
ok($from_decoded_utf8->{heart}, 'My heart is true'); |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
ok($not_decoded->{heart}, 'My heart is true'); |
|
117
|
|
|
|
|
|
|
ok($not_decoded->{heart} ne '♥', 'My heart has been mangled'); |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
is($mech->content_type, 'application/json', 'Got correct content type'); |
|
120
|
|
|
|
|
|
|
is($mech->response->content_type_charset, undef, 'Got correct content-type charset'); |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
local $TODO = "I'm not grokking something"; |
|
123
|
|
|
|
|
|
|
is($from_decoded_utf8->{heart}, '♥', 'Found my true ♥'); # why does this fail? 'â�¥' |
|
124
|
|
|
|
|
|
|
is($manually_decoded->{heart}, '♥', 'Found my true ♥'); # why does this fail? 'â�¥' |
|
125
|
|
|
|
|
|
|
ok($manually_and_JSON_decoded->{heart} ne '♥', 'Found my true ♥'); # WHY DOES THIS WORK (when 'eq')???? somewhere it got UTF8 encoded a second time |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
else { |
|
128
|
|
|
|
|
|
|
# child |
|
129
|
|
|
|
|
|
|
close STDOUT; |
|
130
|
|
|
|
|
|
|
close STDERR; |
|
131
|
|
|
|
|
|
|
exec( $poet->bin_path("run.pl > $run_log 2>&1") ); |
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
1; |