Skip to content

Commit 8a2b191

Browse files
committed
An other go at the 'wide character' bug
It turns out, that in the "old" application/x-www-form-urlencoded interface, the bytea fields are not properly encoded and need an extra round of encoding, before they enter the database. The RESTish/JSONRPC2 interface doesn't seem to have this problem, so we take care to only do this for the form-post interface.
1 parent 79eea78 commit 8a2b191

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

cpanfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ requires 'DBD::SQLite' => '0';
1313
requires 'DBIx::Class' => '0';
1414
requires 'Dancer2::Plugin::DBIC' => '0';
1515
requires 'Moo' => '2';
16-
requires 'Perl5::CoreSmokeDB::Schema' => '1.10';
16+
requires 'Perl5::CoreSmokeDB::Schema' => '1.12';
1717
requires 'namespace::autoclean' => '0';
1818
requires 'Starman' => '0.4015';

environments/development.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ plugins:
1818
options:
1919
RaiseError: 1
2020
PrintError: 1
21+
pg_enable_utf8: -1
2122
development: &dev
2223
schema_class: Perl5::CoreSmokeDB::Schema
2324
dsn: 'dbi:Pg:host=fidodbmaster;dbname=coresmokedb'
2425
options:
2526
RaiseError: 1
2627
PrintError: 1
28+
pg_enable_utf8: -1
2729
default: *dev

lib/Perl5/CoreSmokeDB/API/FreeRoutes.pm

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package Perl5::CoreSmokeDB::API::FreeRoutes;
22
use Moo;
33

4-
our $VERSION = '0.01';
4+
our $VERSION = '0.02';
5+
6+
use Dancer2 appname => 'Perl5::CoreSmokeDB';
57

68
=head1 NAME
79
@@ -21,15 +23,10 @@ Returns the processed Swagger document as C<application/json>
2123
2224
=cut
2325

24-
package Perl5::CoreSmokeDB {
25-
use warnings;
26-
use strict;
27-
use Dancer2;
28-
29-
use Encode qw( encode );
30-
use File::Spec::Functions qw( catfile );
31-
use Time::HiRes qw( time );
32-
use YAML qw( LoadFile );
26+
use Encode qw< encode decode >;
27+
use File::Spec::Functions qw< catfile >;
28+
use Time::HiRes qw< time >;
29+
use YAML qw< LoadFile >;
3330

3431
get('/api/openapi/web.json' => sub {
3532
my $open_api = LoadFile(catfile(config->{openapidir}, 'Web.yml'));
@@ -78,7 +75,18 @@ It uses the global variable C<$::web_api> to access the new API.
7875

7976
post '/report' => sub {
8077
my $start = time();
81-
my $data = from_json(encode('utf-8', params->{json}));
78+
my $data = from_json(encode('utf-8', params->{json}), { utf8 => 1 });
79+
80+
# We need to extra encode() the bytea fields for this interface
81+
my @bytea = qw< compiler_msgs manifest_msgs nonfatal_msgs log_file out_file >;
82+
for my $fld (@bytea) {
83+
if (ref($data->{$fld}) eq 'ARRAY') {
84+
$_ = encode('utf-8', $_) for @{ $data->{$fld} };
85+
}
86+
else {
87+
defined($data->{$fld}) and $data->{$fld} = encode('utf-8', $data->{$fld});
88+
}
89+
}
8290

8391
my $response = do {
8492
no warnings 'once';
@@ -94,11 +102,17 @@ post '/report' => sub {
94102
};
95103

96104
1;
97-
}
98105

99-
1;
106+
=head1 LICENSE
107+
108+
This library is free software; you can redistribute it and/or modify
109+
it under the same terms as Perl itself.
110+
111+
This program is distributed in the hope that it will be useful,
112+
but WITHOUT ANY WARRANTY; without even the implied warranty of
113+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
100114
101-
=head1 AUTHOR
115+
=head1 COPYRIGHT
102116
103117
E<copy> MMXXII - Abe Timmerman <[email protected]>
104118

0 commit comments

Comments
 (0)