Skip to content

Commit

Permalink
Fix utf8 JSON configuration affecting tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrtj committed Jun 26, 2024
1 parent c24abaa commit f4d8736
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Revision history for Kelp
[Changes]
- Kelp::Exception->throw now also works on objects (rethrows an exception)
- Fixed installed config method not returning the default value
- Fixed Kelp::Test being sensitive to utf8 configuration of the JSON encoder
- Config module now allows overriding of the config merging routine

2.11 - 2024-06-25
Expand Down
4 changes: 3 additions & 1 deletion lib/Kelp/Test.pm
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ sub json_content
fail "No JSON decoder" unless $self->app->can('json');
my $result;
try {
$result = $self->app->json->decode($self->res->content);
$result = $self->app->get_encoder(json => 'internal')->decode(
$self->_decode($self->res->content)
);
}
catch {
fail("Poorly formatted JSON");
Expand Down
16 changes: 16 additions & 0 deletions t/charset.t
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,21 @@ subtest 'should set but not not override charset' => sub {
->content_is($text);
};

subtest 'should json_cmp UTF16 without problems with disabled utf8' => sub {
$t->charset('UTF-8'); # set charset for tests

$app->json->utf8(0);
$app->add_route(
'/false' => sub {
my $self = shift;
$self->res->charset('UTF-8');
return {false => 'fałsz'};
}
);

$t->request(GET '/false')
->json_cmp({false => 'fałsz'});
};

done_testing;

0 comments on commit f4d8736

Please sign in to comment.