Skip to content

Commit

Permalink
Merge pull request #30 from cho45/fix-mojibake
Browse files Browse the repository at this point in the history
Fix mojibake #29
  • Loading branch information
moznion committed Mar 17, 2014
2 parents 4674a11 + 3862bff commit ae61d13
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/Ukigumo/Server/Command/Report.pm
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ sub find {
sub _compress_text_data {
my ($self, $row) = @_;
c->config->{enable_compression} or return $row;
$row->{$_} = __compress(encode_utf8($row->{$_})) for qw(vc_log body);
$row->{$_} = __compress($row->{$_}) for qw(vc_log body);
$row;
}

Expand All @@ -262,7 +262,7 @@ sub _uncompress_text_data {
}

sub __compress {
my $bytes = Compress::Zlib::memGzip(\ $_[0]) ;
my $bytes = Compress::Zlib::memGzip(\ encode_utf8($_[0])) ;
if (length($bytes) < length($_[0])) {
return $bytes;
}
Expand Down
20 changes: 14 additions & 6 deletions t/03-compression.t
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ subtest "compress large data" => sub {
my $report = Ukigumo::Server::Command::Report->find(report_id => $id);
is $report->{body}, 'body' x 100;
is $report->{vc_log}, 'vc_log' x 100;
ok utf8::is_utf8($report->{body});
ok utf8::is_utf8($report->{vc_log});
};

subtest "not compress small data" => sub {
Expand All @@ -39,17 +41,19 @@ subtest "not compress small data" => sub {
project => 'MyProj',
branch => 'master',
status => 1,
body => 'body',
vc_log => 'vc_log',
body => 'body あいやー',
vc_log => 'vc_log そいやー',
);

my $row = $c->db->single('report', { report_id => $id })->get_columns;
is $row->{body}, 'body';
is $row->{vc_log}, 'vc_log';
is $row->{body}, 'body あいやー';
is $row->{vc_log}, 'vc_log そいやー';

my $report = Ukigumo::Server::Command::Report->find(report_id => $id);
is $report->{body}, 'body';
is $report->{vc_log}, 'vc_log';
is $report->{body}, 'body あいやー';
is $report->{vc_log}, 'vc_log そいやー';
ok utf8::is_utf8($report->{body});
ok utf8::is_utf8($report->{vc_log});
};

subtest "enable_compression option is false" => sub {
Expand All @@ -70,6 +74,8 @@ subtest "enable_compression option is false" => sub {
my $report = Ukigumo::Server::Command::Report->find(report_id => $id);
is $report->{body}, 'body' x 100;
is $report->{vc_log}, 'vc_log' x 100;
ok utf8::is_utf8($report->{body});
ok utf8::is_utf8($report->{vc_log});
};

subtest "multibytes" => sub {
Expand All @@ -90,6 +96,8 @@ subtest "multibytes" => sub {
my $report = Ukigumo::Server::Command::Report->find(report_id => $id);
is $report->{body}, 'あいやー' x 100;
is $report->{vc_log}, 'そいやー' x 100;
ok utf8::is_utf8($report->{body});
ok utf8::is_utf8($report->{vc_log});
};

done_testing;

0 comments on commit ae61d13

Please sign in to comment.