Skip to content

Commit

Permalink
fixup! [ATAK] Enforce character limit on issue text.
Browse files Browse the repository at this point in the history
Use unicode ellipsis char to save chars.
  • Loading branch information
neprune committed Sep 6, 2023
1 parent c8e9551 commit 0e583ef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions perllib/Open311/Endpoint/Integration/ATAK.pm
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ sub _format_issue_text {
# +2 for the not yet used format directive for detail (%s).
my $max_detail_chars = $char_limit - length($issue_text) + 2;

# We need at least 3 characters of leeway so we can use an ellipsis to indicate
# We need at least 1 character leeway so we can use an ellipsis to indicate
# the detail was truncated.
if ($max_detail_chars < 3 && length($detail) > $max_detail_chars) {
if ($max_detail_chars < 1 && length($detail) > $max_detail_chars) {
die "Issue text is too large, even if we were to truncate the detail before inserting: " . $issue_text;
}

if (length($detail) > $max_detail_chars) {
$detail = substr($detail, 0, $max_detail_chars - 3) . "...";
$detail = substr($detail, 0, $max_detail_chars - 1) . "\x{2026}";
}

return sprintf($issue_text, $detail);
Expand Down
16 changes: 8 additions & 8 deletions t/open311/endpoint/brent.t
Original file line number Diff line number Diff line change
Expand Up @@ -945,23 +945,23 @@ subtest "GET ATAK service request updates OK" => sub {
subtest "ATAK issue text formatting" => sub {

dies_ok { $atak_endpoint->_format_issue_text(
120, 'category', 'location name', 'url', 'title', 'detail'
118, 'category', 'location name', 'url', 'title', 'detail'
) }, "formatting issue text fails when inputs are too big";

my $issue_text = $atak_endpoint->_format_issue_text(
121, 'category', 'location name', 'url', 'title', 'detail'
119, 'category', 'location name', 'url', 'title', 'detail'
);
is $issue_text, "Category: category\nLocation: location name\n\nlocation of problem: title\n\n" .
"detail: ...\n\nurl: url\n\nSubmitted via FixMyStreet\n";
"detail: \x{2026}\n\nurl: url\n\nSubmitted via FixMyStreet\n";

my $issue_text = $atak_endpoint->_format_issue_text(
122, 'category', 'location name', 'url', 'title', 'detail'
$issue_text = $atak_endpoint->_format_issue_text(
120, 'category', 'location name', 'url', 'title', 'detail'
);
is $issue_text, "Category: category\nLocation: location name\n\nlocation of problem: title\n\n" .
"detail: d...\n\nurl: url\n\nSubmitted via FixMyStreet\n";
"detail: d\x{2026}\n\nurl: url\n\nSubmitted via FixMyStreet\n";

my $issue_text = $atak_endpoint->_format_issue_text(
127, 'category', 'location name', 'url', 'title', 'detail'
$issue_text = $atak_endpoint->_format_issue_text(
124, 'category', 'location name', 'url', 'title', 'detail'
);
is $issue_text, "Category: category\nLocation: location name\n\nlocation of problem: title\n\n" .
"detail: detail\n\nurl: url\n\nSubmitted via FixMyStreet\n";
Expand Down

0 comments on commit 0e583ef

Please sign in to comment.