diff --git a/lib/Lacuna/RPC/Inbox.pm b/lib/Lacuna/RPC/Inbox.pm index 26f18cc6..1837b7e1 100644 --- a/lib/Lacuna/RPC/Inbox.pm +++ b/lib/Lacuna/RPC/Inbox.pm @@ -206,10 +206,8 @@ sub send_message { Lacuna::Verify->new(content=>\$subject, throws=>[1005,'Message subject cannot be empty.',$subject])->not_empty; Lacuna::Verify->new(content=>\$subject, throws=>[1005,'Message subject cannot contain any of these characters: (){}<>&;@',$subject])->no_restricted_chars; Lacuna::Verify->new(content=>\$subject, throws=>[1005,'Message subject must be less than 100 characters.',$subject])->length_lt(100); - Lacuna::Verify->new(content=>\$subject, throws=>[1005,'Message subject cannot contain profanity.',$subject])->no_profanity; Lacuna::Verify->new(content=>\$body, throws=>[1005,'Message body cannot be empty.',$body])->not_empty; Lacuna::Verify->new(content=>\$body, throws=>[1005,'Message body cannot contain HTML tags or entities.',$body])->no_tags; - Lacuna::Verify->new(content=>\$body, throws=>[1005,'Message body cannot contain profanity.',$body])->no_profanity; my $empire = $self->get_empire_by_session($session_id); if ($options->{in_reply_to}) { my $reply_to = Lacuna->db->resultset('Lacuna::DB::Result::Message')->find($options->{in_reply_to}); diff --git a/lib/Lacuna/Verify.pm b/lib/Lacuna/Verify.pm index 133bb756..5d55b86b 100644 --- a/lib/Lacuna/Verify.pm +++ b/lib/Lacuna/Verify.pm @@ -3,7 +3,7 @@ package Lacuna::Verify; use Moose; use utf8; no warnings qw(uninitialized); -use Regexp::Common qw(RE_profanity); +use Regexp::Common; use Email::Valid; has content => ( @@ -14,6 +14,7 @@ has content => ( has throws => ( is => 'ro', required => 1, + writer => '_throws', ); sub ok { @@ -51,7 +52,22 @@ sub not_empty { sub no_profanity { my $self = shift; - return $self->ok(lc(${$self->content}) !~ RE_profanity()); + my @bad_words = lc(${$self->content}) =~ /$RE{profanity}{-keep}/g; + if (@bad_words) + { + my %word_count; + $word_count{$_}++ for @bad_words; + my $throws = $self->throws; + my $msg = $throws->[1] . ' ('; + $msg .= join ', ', map { + my $s = $_; + $s .= " (x$word_count{$_})" if $word_count{$_} != 1; + $s; + } sort keys %word_count; + $msg .= ')'; + $throws->[1] = $msg + } + return $self->ok(@bad_words == 0); } sub no_restricted_chars { diff --git a/var/www/public/changes.txt b/var/www/public/changes.txt index cdbe61f8..b7ca0d3e 100644 --- a/var/www/public/changes.txt +++ b/var/www/public/changes.txt @@ -25,6 +25,7 @@ - Fix: log real IPs in login log. - Fix: Speed up N19 news display. - Add: Added flip medal. + - Mod: Profanity filtering is more clear. 3.0908: - Mod: trash_messages_where now defaults to not returning deleted message IDs.