mirror of
https://github.com/pasky/brmelect.git
synced 2025-06-08 10:04:10 +02:00
web-ballot.pl: Add extra sanity checks, mostly inspired by Tim
This commit is contained in:
parent
d4df2bdb18
commit
3b6b809915
1 changed files with 12 additions and 2 deletions
|
@ -80,11 +80,21 @@ if ($q->param('go')) {
|
||||||
|
|
||||||
for my $name (@names) {
|
for my $name (@names) {
|
||||||
my $pref = $q->param($name);
|
my $pref = $q->param($name);
|
||||||
next unless ($pref);
|
next if (not defined $pref or $pref eq '');
|
||||||
|
if (length $pref > 5) {
|
||||||
|
print qq#<p class="error">Length of preference for $name is # . (length $pref) . qq# which is just waaay too much. Please go back and try again.</p>#;
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$pref =~ s/\s*//g;
|
||||||
unless ($pref =~ /^\d+$/) {
|
unless ($pref =~ /^\d+$/) {
|
||||||
|
$pref =~ s/[^\w\d.,-]//g;
|
||||||
print qq#<p class="error">Preference for $name is $pref, which is not a number. Please go back and try again.</p>#;
|
print qq#<p class="error">Preference for $name is $pref, which is not a number. Please go back and try again.</p>#;
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
if ($pref < 1 or $pref > @names) {
|
||||||
|
print qq#<p class="error">Preference for $name is $pref, which is out of the sensible range 1..# . (scalar @names) . qq#. Please go back and try again.</p>#;
|
||||||
|
exit;
|
||||||
|
}
|
||||||
if ($indices[$pref] ne '') {
|
if ($indices[$pref] ne '') {
|
||||||
print qq#<p class="error">Preference for $name is $pref, but this number is already also used for the candidate '$indices[$pref]'. Please go back and try again.</p>#;
|
print qq#<p class="error">Preference for $name is $pref, but this number is already also used for the candidate '$indices[$pref]'. Please go back and try again.</p>#;
|
||||||
exit;
|
exit;
|
||||||
|
@ -107,7 +117,7 @@ if ($q->param('go')) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($indices[1] eq 0) {
|
if ($indices[1] eq '') {
|
||||||
print qq#<p class="error">You must assign a preference (1) to at least one candidate. Please go back and try again.</p>#;
|
print qq#<p class="error">You must assign a preference (1) to at least one candidate. Please go back and try again.</p>#;
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue