summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2015-10-03 10:15:53 +0200
committerYorhel <git@yorhel.nl>2015-10-03 10:15:53 +0200
commitb75eff0f2cce2050c98ec946aac28b390020fdc5 (patch)
tree2e34fdd690cb06b5f5cb12dbecaa3919e0d16ec6 /util
parent30caa944332fbbb9f6f5a4805f5beeee2b8a506c (diff)
Handle JSON data natively when processing form data
No more need for extra json_encode/json_decode calls, and the form_compare() function is more lenient w.r.t. integer/string comparison. This is the improvement I described in commit ed86cfd12b0bed7352e2be525b8e63cb4d6d5448
Diffstat (limited to 'util')
-rwxr-xr-xutil/vndb.pl5
1 files changed, 2 insertions, 3 deletions
diff --git a/util/vndb.pl b/util/vndb.pl
index ca731ca2..3ca6604f 100755
--- a/util/vndb.pl
+++ b/util/vndb.pl
@@ -55,7 +55,7 @@ TUWF::set(
uname => { regex => qr/^[a-z0-9-]*$/, minlength => 2, maxlength => 15 },
gtin => { func => \&gtintype },
editsum => { maxlength => 5000, minlength => 2 },
- json => { func => \&json_validate, inherit => ['json_fields'], default => '[]' },
+ json => { func => \&json_validate, inherit => ['json_fields'], default => [] },
},
);
TUWF::load_recursive('VNDB::Util', 'VNDB::DB', 'VNDB::Handler');
@@ -141,6 +141,7 @@ sub json_validate {
my($val, $opts) = @_;
my $fields = $opts->{json_fields};
my $data = eval { json_decode $val };
+ $_[0] = $@ ? [] : $data;
return 0 if $@ || ref $data ne 'ARRAY';
my %known_fields = map +($_->{field},1), @$fields;
for my $i (0..$#$data) {
@@ -150,7 +151,5 @@ sub json_validate {
$data->[$i] = kv_validate({ field => sub { $data->[$i]{shift()} } }, $TUWF::OBJ->{_TUWF}{validate_templates}, $fields);
return 0 if $data->[$i]{_err};
}
-
- $_[0] = json_encode $data;
return 1;
}