]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Factoids/Statement.pl
avoid reassigning to temp upon decode_utf8
[infobot.git] / src / Factoids / Statement.pl
index 2c5a8e219451af9fa2fcf8f037c608c8c502b0b3..1cc50cb98c47a7fa6e1e4dbe2feb8ba021f999c2 100644 (file)
@@ -15,6 +15,8 @@
 
 # use strict;  # TODO
 
+use Encode qw(decode_utf8);
+
 sub doStatement {
     my ($in) = @_;
 
@@ -58,6 +60,24 @@ sub doStatement {
     if ( $in =~ /(^|\s)(is|are)(\s|$)/i ) {
         my ( $lhs, $mhs, $rhs ) = ( $`, $&, $' );
 
+        # Quit if they are over the limits. Check done here since Core.pl calls
+        # this mid sub and Question.pl needs its own check as well. NOTE: $in is
+        # used in this place since lhs and rhs are really undefined for unwanted
+        # teaching. Mainly, the "is" could be anywhere within a 510 byte or so
+        # block of text, so the total size was choosen since the sole purpose of
+        # this logic is to not hammer the db with pointless factoids that were
+        # only meant to be general conversation.
+        return ''
+          if (
+            length $in <
+            &::getChanConfDefault( 'minVolunteerLength', 2, $chan ) or
+            $param{'addressing'} =~ m/require/i ) and not $addressed;
+        return ''
+          if (
+            length $in >
+            &::getChanConfDefault( 'maxVolunteerLength', 512, $chan ) or
+            $param{'addressing'} =~ m/require/i ) and not $addressed;
+
         # allows factoid arguments to be updated. -lear.
         $lhs =~ s/^(cmd: )?(.*)/$1||'' . lc $2/e;
 
@@ -98,16 +118,15 @@ sub doStatement {
         # verify the update statement whether there are any weird
         # characters.
         ### this can be simplified.
-        foreach ( split //, $lhs . $rhs ) {
-            my $ord = ord $_;
-            if ( $ord > 170 and $ord < 220 ) {
-                &status("statement: illegal character '$_' $ord.");
+        for my $temp ($lhs,$rhs ) {
+           my $temp2 = decode_utf8($temp);
+           if ($temp2 =~ /([^[:print:]])/ or $temp2 =~ /\N{U+FFFD}/) {
+               &status("statement: illegal character '$1' ".ord($1).".");
                 &performAddressedReply(
                     "i'm not going to learn illegal characters");
                 return;
             }
         }
-
         # success.
         return if ( &update( $lhs, $mhs, $rhs ) );
     }