summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2015-09-20 08:47:07 +0200
committerYorhel <git@yorhel.nl>2015-09-20 08:47:07 +0200
commit940b089ea5f02ef9bc80b4b82c320c4e9d2dbb34 (patch)
tree4c9be57fb3a07e8e04b5714623e6f7a40fb06a5a
parentcf8e093eace0f3a86fc42726b09e4f2c9979f40e (diff)
Update usage kv_validate() to upcoming TUWF 1.0
And added new 'page' and 'id' templates for more strict validation.
-rw-r--r--data/lang.txt28
-rw-r--r--lib/VNDB/Handler/Affiliates.pm4
-rw-r--r--lib/VNDB/Handler/Chars.pm18
-rw-r--r--lib/VNDB/Handler/Discussions.pm4
-rw-r--r--lib/VNDB/Handler/Misc.pm2
-rw-r--r--lib/VNDB/Handler/Producers.pm4
-rw-r--r--lib/VNDB/Handler/Releases.pm12
-rw-r--r--lib/VNDB/Handler/Staff.pm17
-rw-r--r--lib/VNDB/Handler/Tags.pm16
-rw-r--r--lib/VNDB/Handler/Traits.pm10
-rw-r--r--lib/VNDB/Handler/ULists.pm18
-rw-r--r--lib/VNDB/Handler/Users.pm34
-rw-r--r--lib/VNDB/Handler/VNBrowse.pm2
-rw-r--r--lib/VNDB/Handler/VNEdit.pm13
-rwxr-xr-xutil/vndb.pl9
15 files changed, 90 insertions, 101 deletions
diff --git a/data/lang.txt b/data/lang.txt
index 3e848784..b830712f 100644
--- a/data/lang.txt
+++ b/data/lang.txt
@@ -16334,7 +16334,7 @@ tr : Aynı grupta [url,_1,_2] niteliği zaten var.
uk : Риса [url,_1,_2] вже існує в цій групі
it : La caratteristica [url,_1,_2] esiste già all'interno dello stesso gruppo.
-:_formerr_tpl_mail
+:_formerr_tpl_email
en : Invalid email address
ru : Некорректный адрес электронной почты
cs : Neplatná e-mailová adresa
@@ -16346,7 +16346,7 @@ tr : Geçersiz e-posta adresi
uk : Неправильна е-мейл адреса
it : Indirizzo email non valido
-:_formerr_tpl_url
+:_formerr_tpl_weburl
en : [_1]: Invalid URL
ru : [_1]: Некорректная ссылка
cs : [_1]: Neplatná URL
@@ -16358,7 +16358,7 @@ tr : [_1]: Geçersiz URL
uk : [_1]: Неправильний URL
it : [_1]: URL non valido
-:_formerr_tpl_asciiprint
+:_formerr_tpl_ascii
en : [_1] may only contain ASCII characters
ru : Поле '[_1]' может содержать лишь символы диапазона ASCII
cs : [_1] smí obsahovat pouze znaky ASCII
@@ -16382,17 +16382,17 @@ tr : [_1]: Geçersiz sayı
uk : [_1]: Неправильний номер
it : [_1]: Non è un numero valido
-:_formerr_tpl_pname
-en : [_1] can only contain lowercase alphanumeric characters and a hyphen, and must start with a letter
-ru : Поле '[_1]' может содержать лишь символы буквенно-цифрового диапазона в нижнем регистре и чёрточку и должно начинаться с буквы
-cs : [_1] smí obsahovat pouze malá písmena, čísla a pomlčku, a musí začínat písmenem
-hu : [_1] egy karakterrel kell kezdődjön és csak kisbetűs alfanumerikus karaktereket és egy kötőjelet tartalmazhat
-nl : [_1] mag alleen kleine letters, cijfers of koppeltekens bevatten, en moet beginnen met een letter
-de : [_1] darf nur aus kleingeschriebenen Buchstaben, Zahlen und Bindestrichen bestehen und muss mit einem Buchstaben anfangen
-es : [_1] puede contener caracteres alfanúmerico en minúscula y un guión, y debe empezar por un carácter
-tr : [_1] sadece küçük harfler, rakamlar ve tire içerebilir; ve bir harf ile başlamalıdır
-uk : Поле [_1] може складатися лише з маленьких літер латинки, цифр і рисок, і має починатися з літери
-it : [_1] può avere solo caratteri minuscoli e trattini, e deve iniziare con una lettera
+:_formerr_tpl_uname
+en*: [_1] can only contain lowercase alphanumeric characters and a hyphen
+ru*: Поле '[_1]' может содержать лишь символы буквенно-цифрового диапазона в нижнем регистре и чёрточку и должно начинаться с буквы
+cs*: [_1] smí obsahovat pouze malá písmena, čísla a pomlčku, a musí začínat písmenem
+hu*: [_1] egy karakterrel kell kezdődjön és csak kisbetűs alfanumerikus karaktereket és egy kötőjelet tartalmazhat
+nl : [_1] mag alleen kleine letters, cijfers of koppeltekens bevatten
+de*: [_1] darf nur aus kleingeschriebenen Buchstaben, Zahlen und Bindestrichen bestehen und muss mit einem Buchstaben anfangen
+es*: [_1] puede contener caracteres alfanúmerico en minúscula y un guión, y debe empezar por un carácter
+tr*: [_1] sadece küçük harfler, rakamlar ve tire içerebilir; ve bir harf ile başlamalıdır
+uk*: Поле [_1] може складатися лише з маленьких літер латинки, цифр і рисок, і має починатися з літери
+it*: [_1] può avere solo caratteri minuscoli e trattini, e deve iniziare con una lettera
:_formerr_tpl_json
en : [_1]: Malformed staff data
diff --git a/lib/VNDB/Handler/Affiliates.pm b/lib/VNDB/Handler/Affiliates.pm
index c353ad49..b180adeb 100644
--- a/lib/VNDB/Handler/Affiliates.pm
+++ b/lib/VNDB/Handler/Affiliates.pm
@@ -108,14 +108,14 @@ sub edit {
if($self->reqMethod eq 'POST') {
return if !$self->authCheckCode;
$frm = $self->formValidate(
- { post => 'rid', required => 1, template => 'int' },
+ { post => 'rid', required => 1, template => 'id' },
{ post => 'priority', required => 0, default => 0, template => 'int' },
{ post => 'hidden', required => 0, default => 0, enum => [0,1] },
{ post => 'affiliate',required => 1, enum => [0..$#{$self->{affiliates}}] },
{ post => 'url', required => 1 },
{ post => 'version', required => 0, default => '' },
{ post => 'price', required => 0, default => '' },
- { post => 'lastfetch',required => 0, min => 0 },
+ { post => 'lastfetch',required => 0, template => 'uint' },
{ post => 'data', required => 0, default => '' },
);
if(!$frm->{_err}) {
diff --git a/lib/VNDB/Handler/Chars.pm b/lib/VNDB/Handler/Chars.pm
index fbafc2fe..b02bce5c 100644
--- a/lib/VNDB/Handler/Chars.pm
+++ b/lib/VNDB/Handler/Chars.pm
@@ -290,15 +290,15 @@ sub edit {
{ post => 'alias', required => 0, maxlength => 500, default => '' },
{ post => 'desc', required => 0, maxlength => 5000, default => '' },
{ post => 'gender', required => 0, default => 'unknown', enum => $self->{genders} },
- { post => 'image', required => 0, default => 0, template => 'int' },
+ { post => 'image', required => 0, default => 0, template => 'id' },
{ post => 'bday', required => 0, default => '', regex => [ qr/^\d{2}-\d{2}$/, mt('_chare_form_bday_err') ] },
- { post => 's_bust', required => 0, default => 0, template => 'int' },
- { post => 's_waist', required => 0, default => 0, template => 'int' },
- { post => 's_hip', required => 0, default => 0, template => 'int' },
- { post => 'height', required => 0, default => 0, template => 'int' },
- { post => 'weight', required => 0, default => 0, template => 'int' },
+ { post => 's_bust', required => 0, default => 0, template => 'uint', max => 32767 },
+ { post => 's_waist', required => 0, default => 0, template => 'uint', max => 32767 },
+ { post => 's_hip', required => 0, default => 0, template => 'uint', max => 32767 },
+ { post => 'height', required => 0, default => 0, template => 'uint', max => 32767 },
+ { post => 'weight', required => 0, default => 0, template => 'uint', max => 32767 },
{ post => 'bloodt', required => 0, default => 'unknown', enum => $self->{blood_types} },
- { post => 'main', required => 0, default => 0, template => 'int' },
+ { post => 'main', required => 0, default => 0, template => 'id' },
{ post => 'main_spoil', required => 0, default => 0, enum => [ 0..2 ] },
{ post => 'traits', required => 0, default => '', regex => [ qr/^(?:[1-9]\d*-[0-2])(?: +[1-9]\d*-[0-2])*$/, 'Incorrect trait format.' ] },
{ post => 'vns', required => 0, default => '', regex => [ qr/^(?:[1-9]\d*-\d+-[0-2]-[a-z]+)(?: +[1-9]\d*-\d+-[0-2]-[a-z]+)*$/, 'Incorrect VN format.' ] },
@@ -350,7 +350,7 @@ sub edit {
}
if(!$id) {
- my $vid = $self->formValidate({ get => 'vid', required => 1, template => 'int'});
+ my $vid = $self->formValidate({ get => 'vid', required => 1, template => 'id'});
$frm->{vns} //= "$vid->{vid}-0-0-primary" if !$vid->{_err};
}
$frm->{$_} //= $b4{$_} for keys %b4;
@@ -479,7 +479,7 @@ sub list {
my($self, $fch) = @_;
my $f = $self->formValidate(
- { get => 'p', required => 0, default => 1, template => 'int' },
+ { get => 'p', required => 0, default => 1, template => 'page' },
{ get => 'q', required => 0, default => '' },
{ get => 'fil', required => 0, default => '' },
);
diff --git a/lib/VNDB/Handler/Discussions.pm b/lib/VNDB/Handler/Discussions.pm
index 7be4f3fe..6029deae 100644
--- a/lib/VNDB/Handler/Discussions.pm
+++ b/lib/VNDB/Handler/Discussions.pm
@@ -284,7 +284,7 @@ sub board {
return $self->resNotFound if $type =~ /(db|an|ge|all)/ && $iid;
my $f = $self->formValidate(
- { get => 'p', required => 0, default => 1, template => 'int' },
+ { get => 'p', required => 0, default => 1, template => 'page' },
);
return $self->resNotFound if $f->{_err};
@@ -391,7 +391,7 @@ sub search {
{ get => 'bq', required => 0, maxlength => 100 },
{ get => 'b', required => 0, multi => 1, enum => $self->{discussion_boards} },
{ get => 't', required => 0 },
- { get => 'p', required => 0, default => 1, template => 'int' },
+ { get => 'p', required => 0, default => 1, template => 'page' },
);
return $self->resNotFound if $frm->{_err};
diff --git a/lib/VNDB/Handler/Misc.pm b/lib/VNDB/Handler/Misc.pm
index 57974c6a..8176d854 100644
--- a/lib/VNDB/Handler/Misc.pm
+++ b/lib/VNDB/Handler/Misc.pm
@@ -192,7 +192,7 @@ sub history {
$id ||= 0;
my $f = $self->formValidate(
- { get => 'p', required => 0, default => 1, template => 'int' },
+ { get => 'p', required => 0, default => 1, template => 'page' },
{ get => 'm', required => 0, default => !$type, enum => [ 0, 1 ] },
{ get => 'h', required => 0, default => 0, enum => [ -1..1 ] },
{ get => 't', required => 0, default => '', enum => [qw|v r p c s a|] },
diff --git a/lib/VNDB/Handler/Producers.pm b/lib/VNDB/Handler/Producers.pm
index 2258fb5a..8314af48 100644
--- a/lib/VNDB/Handler/Producers.pm
+++ b/lib/VNDB/Handler/Producers.pm
@@ -222,7 +222,7 @@ sub edit {
{ post => 'original', required => 0, maxlength => 200, default => '' },
{ post => 'alias', required => 0, maxlength => 500, default => '' },
{ post => 'lang', enum => $self->{languages} },
- { post => 'website', required => 0, maxlength => 250, default => '', template => 'url' },
+ { post => 'website', required => 0, maxlength => 250, default => '', template => 'weburl' },
{ post => 'l_wp', required => 0, maxlength => 150, default => '' },
{ post => 'desc', required => 0, maxlength => 5000, default => '' },
{ post => 'prodrelations', required => 0, maxlength => 5000, default => '' },
@@ -346,7 +346,7 @@ sub list {
my($self, $char) = @_;
my $f = $self->formValidate(
- { get => 'p', required => 0, default => 1, template => 'int' },
+ { get => 'p', required => 0, default => 1, template => 'page' },
{ get => 'q', required => 0, default => '' },
);
return $self->resNotFound if $f->{_err};
diff --git a/lib/VNDB/Handler/Releases.pm b/lib/VNDB/Handler/Releases.pm
index 35cf824c..4c4e7d54 100644
--- a/lib/VNDB/Handler/Releases.pm
+++ b/lib/VNDB/Handler/Releases.pm
@@ -308,8 +308,8 @@ sub edit {
func => [ \&gtintype, 'Not a valid JAN/UPC/EAN code' ] },
{ post => 'catalog', required => 0, default => '', maxlength => 50 },
{ post => 'languages', multi => 1, enum => $self->{languages} },
- { post => 'website', required => 0, default => '', maxlength => 250, template => 'url' },
- { post => 'released', required => 0, default => 0, template => 'int' },
+ { post => 'website', required => 0, default => '', maxlength => 250, template => 'weburl' },
+ { post => 'released', required => 0, default => 0, template => 'uint' },
{ post => 'minage' , required => 0, default => -1, enum => $self->{age_ratings} },
{ post => 'notes', required => 0, default => '', maxlength => 10240 },
{ post => 'platforms', required => 0, default => '', multi => 1, enum => $self->{platforms} },
@@ -475,7 +475,7 @@ sub browse {
my $self = shift;
my $f = $self->formValidate(
- { get => 'p', required => 0, default => 1, template => 'int' },
+ { get => 'p', required => 0, default => 1, template => 'page' },
{ get => 'o', required => 0, default => 'a', enum => ['a', 'd'] },
{ get => 'q', required => 0, default => '', maxlength => 500 },
{ get => 's', required => 0, default => 'title', enum => [qw|released minage title|] },
@@ -565,8 +565,8 @@ sub _fil_compat {
{ get => 'do', required => 0, default => 0, enum => [ 0..2 ] },
{ get => 'ma_m', required => 0, default => 0, enum => [ 0, 1 ] },
{ get => 'ma_a', required => 0, default => 0, enum => $self->{age_ratings} },
- { get => 'mi', required => 0, default => 0, template => 'int' },
- { get => 'ma', required => 0, default => 99999999, template => 'int' },
+ { get => 'mi', required => 0, default => 0, template => 'uint' },
+ { get => 'ma', required => 0, default => 99999999, template => 'uint' },
{ get => 're', required => 0, multi => 1, default => 0, enum => [ 1..$#{$self->{resolutions}} ] },
);
return () if $f->{_err};
@@ -589,7 +589,7 @@ sub relxml {
my $self = shift;
my $f = $self->formValidate(
- { get => 'v', required => 1, multi => 1, mincount => 1, template => 'int' }
+ { get => 'v', required => 1, multi => 1, mincount => 1, template => 'id' }
);
return $self->resNotFound if $f->{_err};
diff --git a/lib/VNDB/Handler/Staff.pm b/lib/VNDB/Handler/Staff.pm
index 5496af11..75a1a97e 100644
--- a/lib/VNDB/Handler/Staff.pm
+++ b/lib/VNDB/Handler/Staff.pm
@@ -201,14 +201,14 @@ sub edit {
$frm = $self->formValidate (
{ post => 'name', maxlength => 200 },
{ post => 'original', required => 0, maxlength => 200, default => '' },
- { post => 'primary', required => 0, template => 'int', default => 0 },
+ { post => 'primary', required => 0, template => 'id', default => 0 },
{ post => 'desc', required => 0, maxlength => 5000, default => '' },
{ post => 'gender', required => 0, default => 'unknown', enum => [qw|unknown m f|] },
{ post => 'lang', enum => $self->{languages} },
{ post => 'l_wp', required => 0, maxlength => 150, default => '' },
- { post => 'l_site', required => 0, template => 'url', maxlength => 250, default => '' },
+ { post => 'l_site', required => 0, template => 'weburl', maxlength => 250, default => '' },
{ post => 'l_twitter', required => 0, maxlength => 16, default => '', regex => [ qr/^\S+$/, mt('_staffe_form_tw_err') ] },
- { post => 'l_anidb', required => 0, template => 'int', default => undef },
+ { post => 'l_anidb', required => 0, template => 'id', default => undef },
{ post => 'aliases', required => 0, maxlength => 5000, default => '' },
{ post => 'editsum', required => 0, maxlength => 5000 },
{ post => 'ihid', required => 0 },
@@ -218,7 +218,7 @@ sub edit {
my $aliases = json_validate($frm, 'aliases',
{ field => 'name', required => 1, maxlength => 200 },
{ field => 'orig', required => 0, maxlength => 200, default => '' },
- { field => 'aid', required => 0, template => 'int', default => 0 },
+ { field => 'aid', required => 0, template => 'id', default => 0 },
);
if(!$frm->{_err}) {
@@ -226,8 +226,7 @@ sub edit {
my %old_aliases = $sid ? ( map +($_->{id} => 1), @{$self->dbStaffAliasIds($sid)} ) : ();
$frm->{primary} = 0 unless exists $old_aliases{$frm->{primary}};
- # normalize alias id to a number so that the comparison works
- # or reset it to zero for newly added aliases.
+ # reset aid to zero for newly added aliases.
$_->{aid} *= $old_aliases{$_->{aid}} ? 1 : 0 for (sort { $a->{name} cmp $b->{name} } @$aliases);
}
if(!$frm->{_err}) {
@@ -295,7 +294,7 @@ sub list {
my ($self, $char) = @_;
my $f = $self->formValidate(
- { get => 'p', required => 0, default => 1, template => 'int' },
+ { get => 'p', required => 0, default => 1, template => 'page' },
{ get => 'q', required => 0, default => '' },
{ get => 'fil', required => 0, default => '' },
);
@@ -367,8 +366,8 @@ sub staffxml {
my $self = shift;
my $q = $self->formValidate(
- { get => 'a', required => 0, multi => 1, template => 'int' },
- { get => 's', required => 0, multi => 1, template => 'int' },
+ { get => 'a', required => 0, multi => 1, template => 'id' },
+ { get => 's', required => 0, multi => 1, template => 'id' },
{ get => 'q', required => 0, maxlength => 500 },
);
return $self->resNotFound if $q->{_err} || !(@{$q->{s}} || @{$q->{a}} || $q->{q});
diff --git a/lib/VNDB/Handler/Tags.pm b/lib/VNDB/Handler/Tags.pm
index f4f8cec3..cc38cdf8 100644
--- a/lib/VNDB/Handler/Tags.pm
+++ b/lib/VNDB/Handler/Tags.pm
@@ -32,7 +32,7 @@ sub tagpage {
my $f = $self->formValidate(
{ get => 's', required => 0, default => 'tagscore', enum => [ qw|title rel pop tagscore rating| ] },
{ get => 'o', required => 0, default => 'd', enum => [ 'a','d' ] },
- { get => 'p', required => 0, default => 1, template => 'int' },
+ { get => 'p', required => 0, default => 1, template => 'page' },
{ get => 'm', required => 0, default => $self->authPref('spoilers') || 0, enum => [qw|0 1 2|] },
{ get => 'fil', required => 0 },
);
@@ -280,7 +280,7 @@ sub taglist {
my $f = $self->formValidate(
{ get => 's', required => 0, default => 'name', enum => ['added', 'name'] },
{ get => 'o', required => 0, default => 'a', enum => ['a', 'd'] },
- { get => 'p', required => 0, default => 1, template => 'int' },
+ { get => 'p', required => 0, default => 1, template => 'page' },
{ get => 't', required => 0, default => -1, enum => [ -1..2 ] },
{ get => 'q', required => 0, default => '' },
);
@@ -346,12 +346,12 @@ sub taglinks {
my $self = shift;
my $f = $self->formValidate(
- { get => 'p', required => 0, default => 1, template => 'int' },
+ { get => 'p', required => 0, default => 1, template => 'page' },
{ get => 'o', required => 0, default => 'd', enum => ['a', 'd'] },
{ get => 's', required => 0, default => 'date', enum => [qw|date tag|] },
- { get => 'v', required => 0, default => 0, template => 'int' },
- { get => 'u', required => 0, default => 0, template => 'int' },
- { get => 't', required => 0, default => 0, template => 'int' },
+ { get => 'v', required => 0, default => 0, template => 'id' },
+ { get => 'u', required => 0, default => 0, template => 'id' },
+ { get => 't', required => 0, default => 0, template => 'id' },
);
return $self->resNotFound if $f->{_err} || $f->{p} > 100;
@@ -473,7 +473,7 @@ sub vntagmod {
return if !$self->authCheckCode;
my $frm = $self->formValidate(
{ post => 'taglinks', required => 0, default => '', maxlength => 10240, regex => [ qr/^[1-9][0-9]*,-?[1-3],-?[0-2]( [1-9][0-9]*,-?[1-3],-?[0-2])*$/, 'meh' ] },
- { post => 'overrule', required => 0, multi => 1, template => 'int' },
+ { post => 'overrule', required => 0, multi => 1, template => 'id' },
);
return $self->resNotFound if $frm->{_err};
@@ -726,7 +726,7 @@ sub tagxml {
my $f = $self->formValidate(
{ get => 'q', required => 0, maxlength => 500 },
- { get => 'id', required => 0, multi => 1, template => 'int' },
+ { get => 'id', required => 0, multi => 1, template => 'id' },
);
return $self->resNotFound if $f->{_err} || (!$f->{q} && !$f->{id} && !$f->{id}[0]);
diff --git a/lib/VNDB/Handler/Traits.pm b/lib/VNDB/Handler/Traits.pm
index a69e8763..98f0b757 100644
--- a/lib/VNDB/Handler/Traits.pm
+++ b/lib/VNDB/Handler/Traits.pm
@@ -25,7 +25,7 @@ sub traitpage {
return $self->resNotFound if !$t;
my $f = $self->formValidate(
- { get => 'p', required => 0, default => 1, template => 'int' },
+ { get => 'p', required => 0, default => 1, template => 'page' },
{ get => 'm', required => 0, default => $self->authPref('spoilers')||0, enum => [qw|0 1 2|] },
{ get => 'fil', required => 0, default => '' },
);
@@ -144,7 +144,7 @@ sub traitedit {
{ post => 'alias', required => 0, maxlength => 1024, default => '', regex => [ qr/^[^,]+$/s, 'No comma allowed in aliases' ] },
{ post => 'description', required => 0, maxlength => 10240, default => '' },
{ post => 'parents', required => !$self->authCan('tagmod'), default => '', regex => [ qr/^(?:$|(?:[1-9]\d*)(?: +[1-9]\d*)*)$/, 'Parent traits must be a space-separated list of trait IDs' ] },
- { post => 'order', required => 0, default => 0, template => 'int', min => 0 },
+ { post => 'order', required => 0, default => 0, template => 'uint' },
);
my @parents = split /[\t ]+/, $frm->{parents};
my $group = undef;
@@ -254,7 +254,7 @@ sub traitlist {
my $f = $self->formValidate(
{ get => 's', required => 0, default => 'name', enum => ['added', 'name'] },
{ get => 'o', required => 0, default => 'a', enum => ['a', 'd'] },
- { get => 'p', required => 0, default => 1, template => 'int' },
+ { get => 'p', required => 0, default => 1, template => 'page' },
{ get => 't', required => 0, default => -1, enum => [ -1..2 ] },
{ get => 'q', required => 0, default => '' },
);
@@ -403,8 +403,8 @@ sub traitxml {
my $f = $self->formValidate(
{ get => 'q', required => 0, maxlength => 500 },
- { get => 'id', required => 0, multi => 1, template => 'int' },
- { get => 'r', required => 0, default => 15, template => 'int', min => 1, max => 200 },
+ { get => 'id', required => 0, multi => 1, template => 'id' },
+ { get => 'r', required => 0, default => 15, template => 'uint', min => 1, max => 200 },
);
return $self->resNotFound if $f->{_err} || (!$f->{q} && !$f->{id} && !$f->{id}[0]);
diff --git a/lib/VNDB/Handler/ULists.pm b/lib/VNDB/Handler/ULists.pm
index 3fd7d41d..5d4fdcf8 100644
--- a/lib/VNDB/Handler/ULists.pm
+++ b/lib/VNDB/Handler/ULists.pm
@@ -84,9 +84,7 @@ sub rlist_e {
my $rid = $id;
if(!$rid) {
- my $f = $self->formValidate(
- { get => 'id', required => 1, template => 'int' }
- );
+ my $f = $self->formValidate({ get => 'id', required => 1, template => 'id' });
return $self->resNotFound if $f->{_err};
$rid = $f->{id};
}
@@ -125,7 +123,7 @@ sub votelist {
return $self->resNotFound if $type eq 'u' && !$own && !(!$obj->{hide_list} || $self->authCan('usermod'));
my $f = $self->formValidate(
- { get => 'p', required => 0, default => 1, template => 'int' },
+ { get => 'p', required => 0, default => 1, template => 'page' },
{ get => 'o', required => 0, default => 'd', enum => ['a', 'd'] },
{ get => 's', required => 0, default => 'date', enum => [qw|date title vote|] },
{ get => 'c', required => 0, default => 'all', enum => [ 'all', 'a'..'z', 0 ] },
@@ -135,7 +133,7 @@ sub votelist {
if($own && $self->reqMethod eq 'POST') {
return if !$self->authCheckCode;
my $frm = $self->formValidate(
- { post => 'vid', required => 1, multi => 1, template => 'int' },
+ { post => 'vid', required => 1, multi => 1, template => 'id' },
{ post => 'batchedit', required => 1, enum => [ -2, -1, 1..10 ] },
);
my @vid = grep $_ && $_ > 0, @{$frm->{vid}};
@@ -229,7 +227,7 @@ sub wishlist {
return $self->resNotFound if !$u || !$own && !(!$u->{hide_list} || $self->authCan('usermod'));
my $f = $self->formValidate(
- { get => 'p', required => 0, default => 1, template => 'int' },
+ { get => 'p', required => 0, default => 1, template => 'page' },
{ get => 'o', required => 0, default => 'd', enum => [ 'a', 'd' ] },
{ get => 's', required => 0, default => 'wstat', enum => [qw|title added wstat|] },
{ get => 'f', required => 0, default => -1, enum => [ -1, @{$self->{wishlist_status}} ] },
@@ -239,7 +237,7 @@ sub wishlist {
if($own && $self->reqMethod eq 'POST') {
return if !$self->authCheckCode;
my $frm = $self->formValidate(
- { post => 'sel', required => 0, default => 0, multi => 1, template => 'int' },
+ { post => 'sel', required => 0, default => 0, multi => 1, template => 'id' },
{ post => 'batchedit', required => 1, enum => [ -1, @{$self->{wishlist_status}} ] },
);
$frm->{sel} = [ grep $_, @{$frm->{sel}} ]; # weed out "select all" checkbox
@@ -334,7 +332,7 @@ sub vnlist {
return $self->resNotFound if !$u || !$own && !(!$u->{hide_list} || $self->authCan('usermod'));
my $f = $self->formValidate(
- { get => 'p', required => 0, default => 1, template => 'int' },
+ { get => 'p', required => 0, default => 1, template => 'page' },
{ get => 'o', required => 0, default => 'a', enum => [ 'a', 'd' ] },
{ get => 's', required => 0, default => 'title', enum => [ 'title', 'vote' ] },
{ get => 'c', required => 0, default => 'all', enum => [ 'all', 'a'..'z', 0 ] },
@@ -346,8 +344,8 @@ sub vnlist {
if($own && $self->reqMethod eq 'POST') {
return if !$self->authCheckCode;
my $frm = $self->formValidate(
- { post => 'vid', required => 0, default => 0, multi => 1, template => 'int' },
- { post => 'rid', required => 0, default => 0, multi => 1, template => 'int' },
+ { post => 'vid', required => 0, default => 0, multi => 1, template => 'id' },
+ { post => 'rid', required => 0, default => 0, multi => 1, template => 'id' },
{ post => 'not', required => 0, default => '', maxlength => 2000 },
{ post => 'vns', required => 1, enum => [ -2, -1, @{$self->{vnlist_status}}, 999 ] },
{ post => 'rel', required => 1, enum => [ -2, -1, @{$self->{rlist_status}} ] },
diff --git a/lib/VNDB/Handler/Users.pm b/lib/VNDB/Handler/Users.pm
index 954923b4..491c573b 100644
--- a/lib/VNDB/Handler/Users.pm
+++ b/lib/VNDB/Handler/Users.pm
@@ -161,7 +161,7 @@ sub login {
return if !$self->authCheckCode;
$frm = $self->formValidate(
{ post => 'usrname', required => 1, minlength => 2, maxlength => 15 },
- { post => 'usrpass', required => 1, minlength => 4, maxlength => 64, template => 'asciiprint' },
+ { post => 'usrpass', required => 1, minlength => 4, maxlength => 64, template => 'ascii' },
);
if(!$frm->{_err}) {
@@ -199,9 +199,7 @@ sub newpass {
my($frm, $u);
if($self->reqMethod eq 'POST') {
return if !$self->authCheckCode;
- $frm = $self->formValidate(
- { post => 'mail', required => 1, template => 'mail' },
- );
+ $frm = $self->formValidate({ post => 'mail', template => 'email' });
if(!$frm->{_err}) {
$u = $self->dbUserGet(mail => $frm->{mail})->[0];
$frm->{_err} = [ 'nomail' ] if !$u || !$u->{id};
@@ -261,8 +259,8 @@ sub setpass {
if($self->reqMethod eq 'POST') {
return if !$self->authCheckCode("/u$u->{id}/setpass?t=$t");
$frm = $self->formValidate(
- { post => 'usrpass', minlength => 4, maxlength => 64, template => 'asciiprint' },
- { post => 'usrpass2', minlength => 4, maxlength => 64, template => 'asciiprint' },
+ { post => 'usrpass', minlength => 4, maxlength => 64, template => 'ascii' },
+ { post => 'usrpass2', minlength => 4, maxlength => 64, template => 'ascii' },
);
push @{$frm->{_err}}, 'passmatch' if $frm->{usrpass} ne $frm->{usrpass2};
@@ -292,10 +290,10 @@ sub register {
if($self->reqMethod eq 'POST') {
return if !$self->authCheckCode;
$frm = $self->formValidate(
- { post => 'usrname', template => 'pname', minlength => 2, maxlength => 15 },
- { post => 'mail', template => 'mail' },
- { post => 'type', regex => [ qr/^[1-3]$/ ] },
- { post => 'answer', template => 'int' },
+ { post => 'usrname', template => 'uname' },
+ { post => 'mail', template => 'email' },
+ { post => 'type', enum => [1..3] },
+ { post => 'answer', template => 'uint' },
);
my $num = $self->{stats}{[qw|vn releases producers|]->[ $frm->{type} - 1 ]};
push @{$frm->{_err}}, 'notanswer' if !$frm->{_err} && ($frm->{answer} > $num || $frm->{answer} < $num*0.995);
@@ -365,13 +363,13 @@ sub edit {
return if !$self->authCheckCode;
$frm = $self->formValidate(
$self->authCan('usermod') ? (
- { post => 'usrname', template => 'pname', minlength => 2, maxlength => 15 },
+ { post => 'usrname', template => 'uname' },
{ post => 'perms', required => 0, multi => 1, enum => [ keys %{$self->{permissions}} ] },
{ post => 'ign_votes', required => 0, default => 0 },
) : (),
- { post => 'mail', template => 'mail' },
- { post => 'usrpass', required => 0, minlength => 4, maxlength => 64, template => 'asciiprint' },
- { post => 'usrpass2', required => 0, minlength => 4, maxlength => 64, template => 'asciiprint' },
+ { post => 'mail', template => 'email' },
+ { post => 'usrpass', required => 0, minlength => 4, maxlength => 64, template => 'ascii' },
+ { post => 'usrpass2', required => 0, minlength => 4, maxlength => 64, template => 'ascii' },
{ post => 'hide_list', required => 0, default => 0, enum => [0,1] },
{ post => 'show_nsfw', required => 0, default => 0, enum => [0,1] },
{ post => 'traits_sexual', required => 0, default => 0, enum => [0,1] },
@@ -463,7 +461,7 @@ sub posts {
return $self->resNotFound if !$u->{id};
my $f = $self->formValidate(
- { get => 'p', required => 0, default => 1, template => 'int' }
+ { get => 'p', required => 0, default => 1, template => 'page' }
);
return $self->resNotFound if $f->{_err};
@@ -557,7 +555,7 @@ sub list {
my $f = $self->formValidate(
{ get => 's', required => 0, default => 'username', enum => [ qw|username registered votes changes tags| ] },
{ get => 'o', required => 0, default => 'a', enum => [ 'a','d' ] },
- { get => 'p', required => 0, default => 1, template => 'int' },
+ { get => 'p', required => 0, default => 1, template => 'page' },
{ get => 'q', required => 0, default => '', maxlength => 50 },
);
return $self->resNotFound if $f->{_err};
@@ -630,7 +628,7 @@ sub notifies {
return $self->htmlDenied if !$u->{id} || $uid != $u->{id};
my $f = $self->formValidate(
- { get => 'p', required => 0, default => 1, template => 'int' },
+ { get => 'p', required => 0, default => 1, template => 'page' },
{ get => 'r', required => 0, default => 0, enum => [0,1] },
);
return $self->resNotFound if $f->{_err};
@@ -651,7 +649,7 @@ sub notifies {
} elsif($self->reqMethod() eq 'POST') {
return if !$self->authCheckCode;
my $frm = $self->formValidate(
- { post => 'notifysel', multi => 1, required => 0, template => 'int' },
+ { post => 'notifysel', multi => 1, required => 0, template => 'id' },
{ post => 'markread', required => 0 },
{ post => 'remove', required => 0 }
);
diff --git a/lib/VNDB/Handler/VNBrowse.pm b/lib/VNDB/Handler/VNBrowse.pm
index c2a923b5..bc8b39b2 100644
--- a/lib/VNDB/Handler/VNBrowse.pm
+++ b/lib/VNDB/Handler/VNBrowse.pm
@@ -18,7 +18,7 @@ sub list {
my $f = $self->formValidate(
{ get => 's', required => 0, default => 'tagscore', enum => [ qw|title rel pop tagscore rating| ] },
{ get => 'o', required => 0, enum => [ 'a','d' ] },
- { get => 'p', required => 0, default => 1, template => 'int' },
+ { get => 'p', required => 0, default => 1, template => 'page' },
{ get => 'q', required => 0, default => '' },
{ get => 'sq', required => 0, default => '' },
{ get => 'fil',required => 0 },
diff --git a/lib/VNDB/Handler/VNEdit.pm b/lib/VNDB/Handler/VNEdit.pm
index 79f439ec..5757f830 100644
--- a/lib/VNDB/Handler/VNEdit.pm
+++ b/lib/VNDB/Handler/VNEdit.pm
@@ -115,7 +115,7 @@ sub edit {
{ post => 'l_encubed', required => 0, default => '', maxlength => 100 },
{ post => 'l_renai', required => 0, default => '', maxlength => 100 },
{ post => 'anime', required => 0, default => '' },
- { post => 'image', required => 0, default => 0, template => 'int' },
+ { post => 'image', required => 0, default => 0, template => 'id' },
{ post => 'img_nsfw', required => 0, default => 0 },
{ post => 'credits', required => 0, default => '[]', maxlength => 5000 },
{ post => 'seiyuu', required => 0, default => '[]', maxlength => 5000 },
@@ -127,13 +127,13 @@ sub edit {
);
push @{$frm->{_err}}, 'badeditsum' if !$nosubmit && (!$frm->{editsum} || lc($frm->{editsum}) eq lc($frm->{desc}));
my $raw_c = !$frm->{_err} && json_validate($frm, 'credits',
- { field => 'aid', required => 1, template => 'int' },
+ { field => 'aid', required => 1, template => 'id' },
{ field => 'role', required => 1, enum => $self->{staff_roles} },
{ field => 'note', required => 0, maxlength => 300, default => '' },
);
my $raw_s = !$frm->{_err} && json_validate($frm, 'seiyuu',
- { field => 'aid', required => 1, template => 'int' },
- { field => 'cid', required => 1, template => 'int' },
+ { field => 'aid', required => 1, template => 'id' },
+ { field => 'cid', required => 1, template => 'id' },
{ field => 'note', required => 0, maxlength => 300, default => '' },
);
@@ -152,7 +152,6 @@ sub edit {
next unless exists $staff{$c->{aid}};
# discard entries with identical name & role
next if $last_c->{aid} == $c->{aid} && $last_c->{role} eq $c->{role};
- $c->{aid} += 0;
push @credits, $c;
$last_c = $c;
}
@@ -164,8 +163,6 @@ sub edit {
for my $s (sort { $a->{aid} <=> $b->{aid} || $a->{cid} <=> $b->{cid} } @$raw_s) {
next unless $staff{$s->{aid}} && $vn_chars{$s->{cid}}; # weed out odd credits
next if $last_s->{aid} == $s->{aid} && $last_s->{cid} == $s->{cid};
- $s->{cid} += 0; # force numeric conversion
- $s->{aid} += 0;
push @seiyuu, $s;
$last_s = $s;
}
@@ -516,7 +513,7 @@ sub scrxml {
die "This page can only be accessed as POST\n" if $self->reqMethod ne 'POST';
# upload new screenshot
- my $num = $self->formValidate({get => 'upload', template => 'int'});
+ my $num = $self->formValidate({get => 'upload', template => 'uint'});
return $self->resNotFound if $num->{_err};
my $param = "scr_upl_file_$num->{upload}";
diff --git a/util/vndb.pl b/util/vndb.pl
index 7a37df04..88281da9 100755
--- a/util/vndb.pl
+++ b/util/vndb.pl
@@ -47,13 +47,10 @@ TUWF::set(
pre_request_handler => \&reqinit,
error_404_handler => \&handle404,
log_format => \&logformat,
- # for compatibility with YAWF
validate_templates => {
- mail => { regex => qr/^[^@<>\s\(\),]+@[^@.<>\s\(\),]+(?:\.[^@.<>\s\(\),]+)+$/ },
- url => { regex => qr/^(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+\*#]*[\w\-\@?^=%&\/~\+#\*])?$/ },
- asciiprint => { regex => qr/^[\x20-\x7E]*$/ },
- int => { regex => qr/^-?[0-9]+$/ },
- pname => { regex => qr/^[a-z0-9-]*$/ },
+ id => { template => 'uint', min => 1, max => 1<<40 },
+ page => { template => 'uint', max => 1000 },
+ uname => { regex => qr/^[a-z0-9-]*$/, minlength => 2, maxlength => 15 },
},
);
TUWF::load_recursive('VNDB::Util', 'VNDB::DB', 'VNDB::Handler');