diff options
author | Dave Arter <davea@mysociety.org> | 2020-02-04 15:38:24 +0000 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2020-02-10 09:54:55 +0000 |
commit | b91a0b4ee71c8f8f2bd2c03ae6fff7249303722c (patch) | |
tree | 0bf9ef3028f04c4b8f3b7611cb15c48be494499e /perllib | |
parent | 806a1b638539d846eca693f97c63c272360bd361 (diff) |
[Zürich] Fix crash on certain /report/ajax/<id> URLs
Attempting to load the /report/ajax/<id> URL for a problem that
had a public response and wasn't in the ‘external’ state was causing
a crash because the call to FixMyStreet::App::View::Web::add_links
in updates_as_hashref was returning a FixMyStreet::Template::SafeString
that the JSON module didn't know how to serialise.
This commit adds a TO_JSON method to SafeString, and ensures the output
of /report/ajax is JSON-encoded with convert_blessed turned on so the
TO_JSON method is called.
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/Template/SafeString.pm | 6 |
2 files changed, 8 insertions, 1 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index 7dfda1a4c..7168e8379 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -299,7 +299,8 @@ sub format_problem_for_display : Private { delete $report_hashref->{created}; delete $report_hashref->{confirmed}; - my $content = encode_json( + my $json = JSON::MaybeXS->new( convert_blessed => 1, utf8 => 1 ); + my $content = $json->encode( { report => $report_hashref, updates => $c->cobrand->updates_as_hashref( $problem, $c ), diff --git a/perllib/FixMyStreet/Template/SafeString.pm b/perllib/FixMyStreet/Template/SafeString.pm index 619bee048..263937b39 100644 --- a/perllib/FixMyStreet/Template/SafeString.pm +++ b/perllib/FixMyStreet/Template/SafeString.pm @@ -69,6 +69,12 @@ sub clone { return $clone; } +sub TO_JSON { + my $self = shift; + + return $$self; +} + 1; __END__ |