Skip to content

Commit

Permalink
improve answerURL response handling
Browse files Browse the repository at this point in the history
escape quote after encoding json
  • Loading branch information
drdrew42 committed Apr 8, 2023
1 parent 964aca4 commit 970b911
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions lib/RenderApp/Controller/Render.pm
Original file line number Diff line number Diff line change
Expand Up @@ -154,24 +154,26 @@ async sub problem {
my $response = shift->result;

$answerJWTresponse->{status} = int($response->code);
if ($response->is_success) {
# answerURL responses are expected to be JSON
if ($response->json) {
# munge data with default response object
$answerJWTresponse = { %$answerJWTresponse, %{$response->json} };
} else {
# otherwise throw the whole body as the message
$answerJWTresponse->{message} = $response->body;
}
elsif ($response->is_error) {
$answerJWTresponse->{message} = '[' . $c->logID . '] ' . $response->message;
}

$answerJWTresponse->{message} =~ s/"/\\"/g;
$answerJWTresponse->{message} =~ s/'/\'/g;
})->
catch(sub {
my $response = shift;
$c->log->error($response);
my $err = shift;
$c->log->error($err);

$answerJWTresponse->{status} = 500;
$answerJWTresponse->{message} = '[' . $c->logID . '] ' . $response;
$answerJWTresponse->{message} = '[' . $c->logID . '] ' . $err;
});

$answerJWTresponse = encode_json($answerJWTresponse);
# this will become a string literal, so single-quote characters must be escaped
$answerJWTresponse =~ s/'/\\'/g;
$c->log->info("answerJWT response ".$answerJWTresponse);

$ww_return_hash->{renderedHTML} =~ s/JWTanswerURLstatus/$answerJWTresponse/g;
Expand Down

0 comments on commit 970b911

Please sign in to comment.