From 2c20e8ca0c98b7c7b6936b7a3679adc2df7d18d6 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 17 Nov 2019 21:04:40 +0100 Subject: csv2json: some input validation --- share/csv2json | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'share/csv2json') 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, -- cgit v1.2.3