diff --git a/README.md b/README.md index 7b7e538..1179bdf 100644 --- a/README.md +++ b/README.md @@ -50,5 +50,4 @@ Add the `-v` option for more verbose output ## TODOs 1. Input validation -1. Filter URLs out of message body 1. Set date in the DB rather than the model diff --git a/cpanfile b/cpanfile index d663315..eef7a1a 100644 --- a/cpanfile +++ b/cpanfile @@ -5,3 +5,4 @@ requires 'Mojolicious::Lite'; requires 'Mojo::Pg'; requires 'Mojolicious::Plugin::TagHelpers::Pagination'; requires 'Mojolicious::Plugin::AssetPack'; +requires 'Regexp::Common::URI'; diff --git a/guestbook-ng.pl b/guestbook-ng.pl index 6dca81a..0373853 100755 --- a/guestbook-ng.pl +++ b/guestbook-ng.pl @@ -6,6 +6,7 @@ use Mojolicious::Lite -signatures; use Mojo::Pg; use List::Util qw{shuffle}; +use Regexp::Common qw{URI}; use Data::Dumper; # Uncomment for debugging # Load the model @@ -69,6 +70,10 @@ any [qw{GET POST}], '/sign' => sub ($c) { my $message = $c->param('message'); my $spam = $c->param('answer') ? 0 : 1; + # No URLs in message body since they have their own field + $spam = + $message =~ /$RE{URI}{HTTP}{-scheme => qr}/ ? 1 : 0; + if ($message) { $c->message->create_post($name, $message, $url, $spam); $c->redirect_to('index');