diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report.pm | 14 | ||||
-rw-r--r-- | t/app/controller/report_inspect.t | 31 |
2 files changed, 43 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index e37e08698..60f7ac903 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -335,8 +335,18 @@ sub inspect : Private { my %update_params = (); if ($permissions->{report_inspect}) { - foreach (qw/detailed_information traffic_information/) { - $problem->set_extra_metadata( $_ => $c->get_param($_) ); + $problem->set_extra_metadata( traffic_information => $c->get_param('traffic_information') ); + + if ( my $info = $c->get_param('detailed_information') ) { + $problem->set_extra_metadata( detailed_information => $info ); + if (length($info) > 172) { + $valid = 0; + push @{ $c->stash->{errors} }, + sprintf( + _('Detailed information is limited to %d characters.'), + $c->cobrand->max_detailed_info_length + ); + } } if ( $c->get_param('defect_type') ) { diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t index 5bbbdff79..be8f12cc5 100644 --- a/t/app/controller/report_inspect.t +++ b/t/app/controller/report_inspect.t @@ -261,6 +261,37 @@ FixMyStreet::override_config { }); }; } + + subtest "detailed_information has max length" => sub { + $user->user_body_permissions->delete; + $user->user_body_permissions->create({ body => $oxon, permission_type => 'report_inspect' }); + $mech->get_ok("/report/$report_id"); + $mech->submit_form_ok({ + button => 'save', + with_fields => { + include_update => 0, + detailed_information => 'XXX172XXX' . 'x' x 163, + } + }); + + $report->discard_changes; + like $report->get_extra_metadata('detailed_information'), qr/XXX172XXX/, 'detailed information saved'; + $mech->content_lacks('limited to 172 characters', "172 charcters of detailed information ok"); + $mech->content_contains('XXX172XXX', "Detailed information field contains submitted text"); + + $mech->submit_form_ok({ + button => 'save', + with_fields => { + include_update => 0, + detailed_information => 'XXX173XXX' . 'x' x 164, + } + }); + $mech->content_contains('limited to 172 characters', "173 charcters of detailed information not ok"); + $mech->content_contains('XXX173XXX', "Detailed information field contains submitted text"); + + $report->discard_changes; + like $report->get_extra_metadata('detailed_information'), qr/XXX172XXX/, 'detailed information not saved'; + }; }; FixMyStreet::override_config { |