From 705a136690534bfef247b3d115a39c6354df131a Mon Sep 17 00:00:00 2001 From: swaggboi Date: Sat, 6 Aug 2022 02:26:53 -0400 Subject: [PATCH] Basic input validation --- PostText.pl | 19 ++++++++++++++----- README.md | 1 - 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/PostText.pl b/PostText.pl index 9b94a2f..320a337 100755 --- a/PostText.pl +++ b/PostText.pl @@ -44,12 +44,21 @@ get '/view', sub ($c) { # Post any [qw{GET POST}], '/post', sub ($c) { - my $thread_author = $c->param('name' ); - my $thread_title = $c->param('title'); - my $thread_body = $c->param('post' ); + my $v; - if ($thread_author && $thread_title && $thread_body) { - $c->thread->create_thread($thread_author, $thread_title, $thread_body); + $v = $c->validation() if $c->req->method eq 'POST'; + + if ($v && $v->has_data) { + my $thread_author = $c->param('name' ) || 'Anonymous'; + my $thread_title = $c->param('title'); + my $thread_body = $c->param('post' ); + + $v->required('name' )->size(1, 63 ); + $v->required('title')->size(1, 127 ); + $v->required('post' )->size(2, 4000); + + $c->thread->create_thread($thread_author, $thread_title, $thread_body) + unless $v->has_error(); return $c->redirect_to('view'); } diff --git a/README.md b/README.md index 0858175..580d92d 100644 --- a/README.md +++ b/README.md @@ -26,5 +26,4 @@ Run the tests locally (against development environment) 1. Moar tests... 1. Pick a date format -1. Validate input 1. **Moar tests!!**