summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-11-17 21:04:40 +0100
committerDaniel Friesel <derf@finalrewind.org>2019-11-17 21:04:40 +0100
commit2c20e8ca0c98b7c7b6936b7a3679adc2df7d18d6 (patch)
tree1a9e0c6252cbbd24f4c2d989461e31ab404226f4 /share
parent3d845879adfa68be120b57a2a57184ccd1cc337b (diff)
csv2json: some input validation
Diffstat (limited to 'share')
-rwxr-xr-xshare/csv2json15
1 files changed, 15 insertions, 0 deletions
diff --git a/share/csv2json b/share/csv2json
index a91bac9..1cfd3ee 100755
--- a/share/csv2json
+++ b/share/csv2json
@@ -18,6 +18,21 @@ shift @csv_lines;
for my $line (@csv_lines) {
if ( $csv->parse($line) ) {
my ( $name, $ds100, $uic, $lat, $lon ) = $csv->fields;
+
+ if ( not $name ) {
+ say "Station name is mandatory -- skipping this line: $line";
+ next;
+ }
+ if ( not $ds100 ) {
+ say "DS100 is mandatory at the moment -- skipping this line: $line";
+ next;
+ }
+ if ( not $uic or $uic !~ m{ ^ \d+ $ }x ) {
+ say
+"UIC is mandatory and must be numeric -- skipping this line: $line";
+ next;
+ }
+
my $station = {
name => $name,
ds100 => $ds100,