[pve-devel] [PATCH common 1/3] trim event and check if empty
Dominik Csapak
d.csapak at proxmox.com
Tue Jun 13 11:25:33 CEST 2017
give a meaningful error if it is empty and disallow it instead of having
an implicit default (the default should be set by the component using
the calendarevent, not the calendarevent itself)
also add regression tests
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
src/PVE/CalendarEvent.pm | 7 +++++++
test/calendar_event_test.pl | 12 ++++++++++++
2 files changed, 19 insertions(+)
diff --git a/src/PVE/CalendarEvent.pm b/src/PVE/CalendarEvent.pm
index a053f38..b27e968 100644
--- a/src/PVE/CalendarEvent.pm
+++ b/src/PVE/CalendarEvent.pm
@@ -5,6 +5,7 @@ use warnings;
use Data::Dumper;
use Time::Local;
use PVE::JSONSchema;
+use PVE::Tools qw(trim);
# Note: This class implements a parser/utils for systemd like calender exents
# Date specification is currently not implemented
@@ -36,6 +37,12 @@ sub pve_verify_calendar_event {
sub parse_calendar_event {
my ($event) = @_;
+ $event = trim($event);
+
+ if ($event eq '') {
+ die "unable to parse calendar event - event is empty\n";
+ }
+
my $parse_single_timespec = sub {
my ($p, $max, $matchall_ref, $res_hash) = @_;
diff --git a/test/calendar_event_test.pl b/test/calendar_event_test.pl
index 9c2bf46..5416255 100755
--- a/test/calendar_event_test.pl
+++ b/test/calendar_event_test.pl
@@ -145,6 +145,18 @@ my $tests = [
'0..80',
{ error => "range end '80' out of range" },
],
+ [
+ ' mon 0 0 0',
+ { error => "unable to parse calendar event - unused parts" },
+ ],
+ [
+ '',
+ { error => "unable to parse calendar event - event is empty" },
+ ],
+ [
+ ' mon 0 0',
+ { error => "unable to parse calendar event - unused parts" },
+ ],
];
foreach my $test (@$tests) {
--
2.11.0
More information about the pve-devel
mailing list