summary history branches tags files
commit:4b3810d01560e3d587f55c117679010aaa260f2c
author:Trevor Bentley
committer:Trevor Bentley
date:Mon Aug 7 18:48:59 2017 +0200
parents:c108cdf752e92baa501a3f6f88f1210b6fd9864c
Handle stray spaces in INI alarm entries
diff --git a/src/webapi/mod.rs b/src/webapi/mod.rs
line changes: +7/-6
index cb02f57..df577e5
--- a/src/webapi/mod.rs
+++ b/src/webapi/mod.rs
@@ -297,7 +297,7 @@ impl fmt::Display for AlarmRepeat {
 impl FromStr for AlarmRepeat {
     type Err = String;
     fn from_str(s: &str) -> Result<Self, Self::Err> {
-        match s {
+        match s.trim() {
             "weekdays" => Ok(AlarmRepeat::Weekdays),
             "weekends" => Ok(AlarmRepeat::Weekends),
             _ => Ok(AlarmRepeat::Daily),
@@ -334,11 +334,12 @@ impl FromStr for AlarmConfig {
         let hour = time_fields.next().ok_or("Missing hour")?;
         let minute = time_fields.next().ok_or("Missing minute")?;
         Ok(AlarmConfig {
-            hour: hour.parse().unwrap(),
-            minute: minute.parse().unwrap(),
-            context: context.to_owned(),
-            repeat: AlarmRepeat::from_str(repeat).unwrap(),
-            device: device.to_owned(),
+            hour: hour.trim().parse().unwrap_or(0),
+            minute: minute.trim().parse().unwrap_or(0),
+            context: context.trim().to_owned(),
+            repeat: AlarmRepeat::from_str(repeat)
+                .unwrap_or(AlarmRepeat::Daily),
+            device: device.trim().to_owned(),
         })
     }
 }