diff options
author | Matthew Somerville <matthew@mysociety.org> | 2020-06-09 13:46:59 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2020-06-09 13:47:47 +0100 |
commit | f706b89ef794ed3d16c015842d6052d03a5d39ef (patch) | |
tree | 3581c6457b596872f017da89d0b524a74a680802 | |
parent | abc63a85b47bbc6b9e81c8256a226864ac7fe0ce (diff) |
Fix double encoding of per-category templates.
encode_json encodes to UTF-8, and then
he output was being encoded again.
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/Roles/ContactExtra.pm | 2 | ||||
-rw-r--r-- | t/app/model/responsetemplate.t | 8 |
3 files changed, 7 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bd70243c..733ad04c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - bin/update-schema PostgreSQL 12 compatibility. #3043 - Make sure category shown in all its groups when reporting. - Do not remove any devolved contacts. + - Fix double encoding of per-category templates. - Admin improvements: - Display user name/email for contributed as reports. #2990 - Interface for enabling anonymous reports for certain categories. #2989 diff --git a/perllib/FixMyStreet/Roles/ContactExtra.pm b/perllib/FixMyStreet/Roles/ContactExtra.pm index e78d9b53f..73b1d3e6a 100644 --- a/perllib/FixMyStreet/Roles/ContactExtra.pm +++ b/perllib/FixMyStreet/Roles/ContactExtra.pm @@ -46,7 +46,7 @@ sub by_categories { || (grep { $_->contact_id == $contact->get_column('id') } $_->$join_table) } @results; @ts = $rs->map_extras(@ts); - $extras{$contact->category} = encode_json(\@ts); + $extras{$contact->category} = JSON::XS->new->encode(\@ts); } return \%extras; diff --git a/t/app/model/responsetemplate.t b/t/app/model/responsetemplate.t index 9efc7e3b4..29c41a0e0 100644 --- a/t/app/model/responsetemplate.t +++ b/t/app/model/responsetemplate.t @@ -1,3 +1,4 @@ +use utf8; use FixMyStreet::TestMech; use JSON::MaybeXS; @@ -7,7 +8,7 @@ my $area_id = 2651; my $body = $mech->create_body_ok($area_id, 'Edinburgh Council'); my $c1 = $mech->create_contact_ok(category => 'Potholes', body_id => $body->id, email => 'p'); my $c2 = $mech->create_contact_ok(category => 'Graffiti', body_id => $body->id, email => 'g'); -my $t1 = FixMyStreet::DB->resultset('ResponseTemplate')->create({ body_id => $body->id, title => "Title 1", text => "Text 1" }); +my $t1 = FixMyStreet::DB->resultset('ResponseTemplate')->create({ body_id => $body->id, title => "Title 1", text => "Text 1 ⛄" }); my $t2 = FixMyStreet::DB->resultset('ResponseTemplate')->create({ body_id => $body->id, title => "Title 2", text => "Text 2", state => 'investigating' }); my $t3 = FixMyStreet::DB->resultset('ResponseTemplate')->create({ body_id => $body->id, title => "Title 3", text => "Text 3" }); $t1->add_to_contacts($c1); @@ -17,12 +18,13 @@ my @contacts = FixMyStreet::DB->resultset('Contact')->not_deleted->search( { bod subtest 'by_categories returns allresponse templates grouped by category' => sub { my $templates = FixMyStreet::DB->resultset('ResponseTemplate')->by_categories(\@contacts, body_id => $body->id); - my $potholes = decode_json($templates->{Potholes}); - my $graffiti = decode_json($templates->{Graffiti}); + my $potholes = JSON::MaybeXS->new->decode($templates->{Potholes}); + my $graffiti = JSON::MaybeXS->new->decode($templates->{Graffiti}); is scalar @$potholes, 2, 'Potholes have 2 templates'; is scalar @$graffiti, 2, 'Graffiti has 2 templates'; is $graffiti->[0]->{state}, 'investigating', 'Graffiti first template has right state'; + is $potholes->[0]->{id}, 'Text 1 ⛄', 'Pothole first template has right text'; }; done_testing; |