Filter URLs out of message body

This commit is contained in:
swagg boi 2022-01-02 02:01:45 -05:00
parent 26aa2ba19f
commit baca0cd515
3 changed files with 6 additions and 1 deletions

View file

@ -50,5 +50,4 @@ Add the `-v` option for more verbose output
## TODOs ## TODOs
1. Input validation 1. Input validation
1. Filter URLs out of message body
1. Set date in the DB rather than the model 1. Set date in the DB rather than the model

View file

@ -5,3 +5,4 @@ requires 'Mojolicious::Lite';
requires 'Mojo::Pg'; requires 'Mojo::Pg';
requires 'Mojolicious::Plugin::TagHelpers::Pagination'; requires 'Mojolicious::Plugin::TagHelpers::Pagination';
requires 'Mojolicious::Plugin::AssetPack'; requires 'Mojolicious::Plugin::AssetPack';
requires 'Regexp::Common::URI';

View file

@ -6,6 +6,7 @@
use Mojolicious::Lite -signatures; use Mojolicious::Lite -signatures;
use Mojo::Pg; use Mojo::Pg;
use List::Util qw{shuffle}; use List::Util qw{shuffle};
use Regexp::Common qw{URI};
use Data::Dumper; # Uncomment for debugging use Data::Dumper; # Uncomment for debugging
# Load the model # Load the model
@ -69,6 +70,10 @@ any [qw{GET POST}], '/sign' => sub ($c) {
my $message = $c->param('message'); my $message = $c->param('message');
my $spam = $c->param('answer') ? 0 : 1; 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<https?>}/ ? 1 : 0;
if ($message) { if ($message) {
$c->message->create_post($name, $message, $url, $spam); $c->message->create_post($name, $message, $url, $spam);
$c->redirect_to('index'); $c->redirect_to('index');