Skip to content

Commit

Permalink
Vesta: improve errors on bogus text
Browse files Browse the repository at this point in the history
  • Loading branch information
rjbs committed Sep 7, 2023
1 parent 6b167f4 commit eef56de
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions lib/Synergy/VestaUtil.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package Synergy::VestaUtil;
use experimental qw(signatures);
use utf8;

use List::Util qw(uniq);
use MIME::Base64 ();

my %CHAR_FOR = (
Expand Down Expand Up @@ -182,8 +183,8 @@ sub _text_to_board ($self, $text) {
sub text_to_board ($self, $text) {
$text = uc $text;

unless ($self->_text_is_valid($text)) {
return (undef, "Sorry, I can't post that to the board.");
if (my $text_problem = $self->_problem_with_text($text)) {
return (undef, $text_problem);
}

my $post = $self->_text_to_board($text);
Expand All @@ -195,11 +196,19 @@ sub text_to_board ($self, $text) {
return $post;
}

sub _text_is_valid ($self, $text) {
sub _problem_with_text ($self, $text) {
if (length $text > 6 * 22) {
return "That text is too long. The limit is 132 characters (six rows of 22)."
}

# This feels pretty thing. -- rjbs, 2021-05-31
return if $text =~ m{[^ 0-9A-Z!@#\$\(\)\-\+&=;:'"%,./?°🟥🟧🟨🟩🟦🟪⬜️]};
return if length $text > 6 * 22;
return 1;
my $unwanted = $text =~ s{[ 0-9A-Z!@#\$\(\)\-\+&=;:'"%,./?°🟥🟧🟨🟩🟦🟪⬜️]}{}gr;

return unless $unwanted;

$unwanted = join q{}, sort uniq split //, $unwanted;

return "That text contains characters you can't use. Here they are: $unwanted";
}

1;

0 comments on commit eef56de

Please sign in to comment.